User-Level Native Thread Primitives (GThread) Library White Paper (G06.27+, H06.03+, J06.03+)

User-Level Native Thread Primitives (GThread Library) 02/15/2012
540065-004 Page 40 of 44
If GT_BAD_SWAPTIONS is returned, the thread control block specified on the call to
GTHREAD_INITIATE_ has not been properly set up and therefore cannot be activated until
successfully initialized (by calling GTHREAD_INITIATE_ with a valid Swaptions argument).
Some minor adjustments to the percentage value specified are performed for alignment purposes.
If an adjustment is necessary, the percentage value is rounded down to the closest alignment
boundary.
The specified RegPerCent (before any adjustment) also determines treatment of the stack_delta
parameter to GTH_STACK_CHECK_ACTIVE_ and GTH_STACK_CHECK_THREAD_:
mem_delta = stack_delta;
reg_delta = stack_delta * RegPerCent / (100 – RegPerCent).
Once again it needs to be emphasized that this feature is optional, if the default ratio proves
satisfactory. Using this interface requires knowledge of how both the mem and reg stacks grow
given a specific client implementation. This knowledge can be obtained by careful code analysis,
empirical data, or both.
3.6.2.2. Protected Static Stacks
For protected stacks on TNS/E, the initial sizes of the memory and register stack areas, as well as
the guard area, are determined when the stack is created by calling STACK_ALLOCATE_().
That function supports a ratio option similar to that of GTHREAD_INITIATE_, with a default
ratio between memory and register stacks. It also supports a growth ratio option, as described in
the second bullet below.
The following considerations apply to protected stack usage:
The memory, register and guard areas of the stack are each multiples of 16 KB in size, so the
whole stack size is such a multiple.
If the stack is allocated with growth space, the guard area can be larger than its specified
minimum. The stack allocation must be larger than the minimum (48 KB on TNS/E). When
the operating system detects overflow of either the memory or register stack, it attempts to
grow that portion at the expense of any excess guard area. This facility allows the system to
adjust the reg/mem ratio automatically. Once such an adjustment is made, it is permanent for
the life of that protected stack.
A protected stack is an object (a memory segment) created and managed by the operating
system; allocating or deallocating the object is somewhat more expensive than calling
malloc() or free() for space from the process heap. Therefore, it may be worthwhile for an
application or thread package to cache and reuse stacks, especially if it needs to initiate and
terminate threads frequently.
3.6.2.3. Stack Allocation in LP64 Processes
Allocating a stack space from the default process heap (for example malloc()) is not viable in a
64-bit OSS process, because the default heap is in a 64-bit address space and the stacks are in 32-
bit-address space.
You can use the following alternatives: