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 35 of 44
,{swap-area length} -- Length
,GTS_SWAPPED -- swapped thread
,@InitialProc -- proc for thread
,Arg -- ArgStart
,$LEN(Arg)*$OCCURS(Arg) -- ArgLen
,@Thread^Terminate -- FinalProc
) THEN -- error
{link the new thread onto the ready list}
Termination:
Thread^Terminate(Thread) is the thread termination procedure passed as FinalProc to
GTHREAD_INITIATE_. Thread^Terminate is invoked automatically when the thread InitialProc
exits; a thread may also call it explicitly to terminate itself:
{ready any threads waiting for the completion of this one};
{link this thread onto the package's DeadThreadList};
{ready the Undertaker thread};
Thread^Suspend;
The Undertaker thread, created by Thread^Module^Init, removes any threads from the
DeadThreadList and passes them to Thread^Dispose.
Thread^Dispose(Thread) cleans up the remains of a thread:
GTHREAD_TERMINATE_(Thread);
IF {recycling threads} THEN
{link Thread onto FreeThreadList}
ELSE
{return thread resources to the heap};
An alternative approach to thread termination could use:
GTHREAD_LONGJMP_(MainCB,$DBL(@CurThread),GTH_NULL_PROCADDR);
Code at the resumption point of the unthreaded code would recognize that the value returned from
GTHREAD_SETJMP_ was not 0 or 1, and perform (or schedule) the thread disposition, including a
call to GTHREAD_TERMINATE_.
Suspend current thread:
Thread^Suspend(), the facility to block a thread, is a DEFINE:
DEFINE Thread^Suspend = GTHREAD_SETJMP_(CurThread,@Thread^Swapout)#;