User-Level Native Thread Primitives (GThread) Library White Paper (G06.26+)

User-Level Native Thread Primitives (GThread Library) 03/31/2005
Hewlett-Packard Company--540065-001 Page 39 of 46
-- Adjust environment and invoke Thread^SwapIn:
GTHREAD_SWAPIN_SETUP_(NextThread,Thread^SwapIn);
-- Does not return; Thread^SwapOut LONGJMPs to top of loop.
END;
Thread^SwapIn(NextThread) readies a thread for execution and activates it:
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).