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 37 of 46
Arg[0] := P1;
Arg[1] := P2;
Arg[3] := P3;
IF GTHREAD_INITIATE_
(Thread -- designates GThread_CB
,MainCB -- master CB
,{swap-area address} -- Start
,{swap-area length} -- Length
,GTS_SWAPPED -- swapped thread
,@InitialProc -- proc for thread
,Arg,$LEN(Arg)*$OCCURS(Arg) -- ArgStart,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);