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 8 of 46
2.3. Thread Structures
The basic control structure for a thread is a control block called a GThread_CB. Each thread is identified
to the primitive routines by a reference to its GThread_CB; this address is used as a handle. A thread
package may expose this handle to its clients, or may use some other identification (such as an index into
an array of GThread_CB pointers). For compactness, the following structure definitions and parameter
specifications use "GThreadCB" as a type, whereas TAL, pTAL, and EpTAL actually need structure
pointers (see GTHREAD_CB define).
The program must provide a GThread_CB and a stack or swap area for each thread it creates. A thread
package can include a GThread_CB as a substruct or overlay of a larger structure associated with its own
thread implementation. For simplicity, especially in diagnostic situations, the GThread_CB fields should
occur at the front of the structure.
The program must provide a GThread_CB for the original thread of the process. In this document, this
object is called "MainCB," which is the name of the formal parameter which is passed in several
GThread procedures. The program must retain the MainCB as global state; for native threads its location
is recorded in process state for possible diagnostic use. In a swapping model using peer protocol, the
program must also supply a stack swap area for the main thread.
The program should typically maintain a global pointer to the current GThread_CB. Within this
document, this pointer is called "CurThread".
Some of the GThread_CB contents are private to GThread; others are shared with the program. On
TNS/R platforms, all the elements shown below are accessible to clients. On TNS/E platforms, only
LinkNext, LinkPrev, and GTh_Marker are accessible to clients. Several fields are also available to the
NonStop operating system for diagnostic purposes.
The "GThread_CB" structure contains the following:
GThreadCB LinkNext, LinkPrev
are reserved for the program for linking the thread onto lists (or any other purpose). These fields are
not used by the GThread primitives.
INT(32) GTh_Marker
is an eye-catcher and version field. It is set to the value of the GTHREAD_VERSION literal by the
GTHREAD_INITIATE_ procedure, and destroyed by the GTHREAD_TERMINATE_ procedure.
GThreadCB ThreadNext, ThreadPrev
are links to the next (younger) and previous (older) thread currently defined in this process. These
fields in MainCB anchor a doubly linked list. GTHREAD_INITIATE_ and
GTHREAD_TERMINATE_ link and de-link new and defunct threads; the GTHREAD_INITIALIZE_
procedure initializes the anchors. The list is available to the NonStop operating system for diagnostic
use.