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 26 of 46 
2.10.  Saving and Restoring Stacks 
GTH_STACK_SAVE_( GThread_CB cb ) 
Description: 
Performs a copy (save) of the current thread’s runtime stack as part of suspending current thread 
execution (dispatching another thread). Callable only for a swapped thread. This replaces accessing 
the thread control block elements SwapArea, StackStart, StackUsed, and performing the copy of 
the stack to the save area from the runtime stack area. 
Input: 
cb - The address of the current thread control block. 
Return: int16 
Returns zero if save completed successfully. nonzero indicates the copy failed due to a static thread 
model, a discontiguous swap area, or insufficient swap space. 
Considerations: 
This routine must be called after GTHREAD_SETJMP_ or by a function passed to be called by 
GTHREAD_SETJMP_. See sections 3.2 and 3.6.3.1. The routine does not validate whether the 
thread control block supplied belongs to the currently executing thread. If the control block of a 
suspended thread is provided, corruption of the specified thread’s runtime environment occurs. 
GTH_STACK_RESTORE_( GThread_CB cb ) 
Description: 
Performs a restore of the target thread’s runtime stack as part of dispatching that thread. Callable 
only for a swapped thread. This replaces accessing the thread control block elements SwapArea, 
StackStart, StackUsed, and performing the copy of the stack from the save area back to the runtime 
stack area. 
Input: 
cb - The address of the target thread control block whose stack needs to be restored. 
Return: int16 
Returns zero if restore completed successfully. nonzero indicates the restore failed due to a static 
thread model or a discontiguous swap area. 
Considerations: 
The routine does not validate that the thread control block supplied belongs to the currently 
executing thread. If the control block of a suspended thread is provided, corruption of the specified 
thread’s runtime environment occurs. This interface has the same requirements as the original 
approach where the client performed the restoration function manually – the interface must be called 
within the target routine specified in a call to GTHREAD_SWAPIN_SETUP_. 










