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 34 of 46
3. Usage
The following sections use sketched pTAL/EpTAL examples to illustrate usage of the GThread
primitives for several multithreading models. All models declare one GThread_CB structure named
MainCB for the original thread.
3.1. Native Static
The static model is the simplest to implement. The bare essentials of a simple native-only
implementation are sketched.
Initialization:
IF GTHREAD_INITIALIZE_(GTHREAD_VERSION,MainCB) THEN
...; -- Error: version mismatch
GTHREAD_SETJMP_(MainCB,GTH_NULL_PROCADDR);
IF GTHREAD_ORIGIN_SET_(MainCB) THEN
...; -- Unexpected error: program failure
Setting the Stack Origin in MainCB is essential for swapped threads; it is necessary for static threads if
GTH_STACK_USED_ or any of the four GTH_STACK_CHECK⦠queries will be called with
MainCB.
Initiation:
{allocate GThread_CB};
{allocate stack area};
IF GTHREAD_INITIATE_(CB -- designates GThread_CB
,MainCB -- designates initial CB
,Start,Length -- designate stack area
,GTS_STATIC -- specifies static thread
,@InitialProc -- designates proc for thread
,ArgStart,ArgLen -- designate argument list
,@FinalProc -- designate termination proc
) THEN -- error
In a peer protocol, the thread switching logic might be:
@NextThread := {next thread selected to run};