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 21 of 46
GTH_ STACK_CHECK_THREAD_( GThread_CB cb, int32 stack_delta )
Description:
Permits a client to determine whether there is a specified amount of stack space available on a static
thread using stack pointer information captured on the last call to GTHREAD_SETJMP_ for the
specified thread. Callable only for a static thread. This replaces accessing the thread control block
elements StackSize and StackUsed.
Input:
cb - The address of the thread control block to check.
stack_delta - An indication of how much bigger the mem stack could potentially grow, in bytes.
Return: int16
Returns zero if there is available stack space.
Returns nonzero if:
• The thread model is swapped
• Stack space wasn’t allocated
• A negative stack_delta was supplied
• There is insufficient stack space available after applying stack_delta
Considerations:
This routine is used to detect if sufficient stack space is available based on the stack pointer
information captured in the last call to GTHREAD_SETJMP_ by the specified thread. The routine
applies stack_delta to the captured stack pointer, and compares the resulting value to the stack area
allocated. If the resulting value is outside the allocated area, this routine returns an indication that
there is insufficient stack space. A value of zero for stack_delta is valid; it results in a check to see
if an overflow condition existed at the time GTHREAD_SETJMP_ was called to capture stack
pointer information.
On TNS/E native platforms both the reg and mem stacks are checked. stack_delta is treated as the
memory ‘stack delta’ and a reg ‘stack delta’ is implicitly calculated from stack_delta. The implicit
calculation is based on the ‘ratio’ of mem stack to reg stack size that was established for the
specified thread at initialization time – refer to Section 3.6.2 for more details.
This interface returns information based on the last call to GTHREAD_SETJMP_, or to
GTHREAD_INITIATE_ if GTHREAD_SETJMP_ has not yet been called. This interface is
intended for use on suspended threads. For an active thread, the results are accurate only within the
function that most recently called GTHREAD_SETJMP_.