User-Level Native Thread Primitives (GThread) Library White Paper (G06.27+, H06.03+, J06.03+)
User-Level Native Thread Primitives (GThread Library) 02/15/2012
540065-004 Page 37 of 44
This procedure must be called via GTHREAD_SWAPIN_SETUP_, so its activation record (stack
frame) lies deeper than those of the procedures being copied onto the stack(s).
GTH_STACK_RESTORE_(NextThread);
@CurThread := @NextThread;
GTHREAD_LONGJMP_(NextThread,1d
,IF @NextThread = @DebugThread THEN @DEBUG
ELSE GTH_NULL_PROCADDR);
The preceding statement illustrates a use of the Callee parameter of GTHREAD_LONGJMP_: a
particular thread can be made to enter debug the next time it is resumed.
If the alternative thread termination approach mentioned previously were implemented, Thread^Dispatch
would save the GTHREAD_SETJMP_ result, and select one of three paths based upon that value:
1: Do nothing but proceed to WHILE loop, as above
0: Perform initialization/error check, as above; then proceed
else: Terminate designated thread; then proceed
3.3. Architecture-Selected Models
A package could run swapped TNS threads and static native threads by making the stack-copying
statements conditional in the swap-in and swap-out code:
IF_TNS__(GTH_STACK_SAVE_(CTh));
making the call on GTHREAD_SWAPIN_SETUP_ conditional:
IF_TNS__(GTHREAD_SWAPIN_SETUP_(thread,&Resume)
,Resume(thread));
and conditionally passing Swaptions to GTHREAD_INITIATE_:
,IF_TNS__(GTS_SWAPPED,GTS_STATIC).
3.4. Mixed Models
It is possible for the same process to have some threads swapped and some static. This approach is useful
if some threads are frequently dispatched and have predictable stack sizes, while other threads are less
often dispatched but have unpredictable sizes. Using static threads for the often-dispatched threads
improves performance significantly, but the stack overflow detection of swapped stacks and the ability to
resize the swap area can be important for the less predictable threads.
Similarly, the use of master and peer protocol can be mixed. Only a swapped thread or the Main thread
can dispatch a swapped thread, as these use the Main stack. Therefore, it is convenient to operate the