Thread stack attributes

Three attributes allow POSIX applications to control their threads' stack usage: stackaddr, stacksize, and guardsize.

The stackaddr attribute contains the address of application-provided storage to be used as the initial stack segment. This storage is referred to as an "application-managed stack".

The stacksize attribute controls the size of the stack. In an SUSv3 application, calls to pthread_attr_setstacksize() or pthread_attr_setstack() must provide a stacksize of at least PTHREAD_STACK_MIN.If not provided, the initial increment size is derived from the STACK64/THREADSTACK64 runtime options in AMODE 64, or STACK/THREADSTACK otherwise.

When used in conjunction with application-managed stack, the size of the storage must be a multiple 4K on ILP32 (AMODE31) and 1M on L64 (AMODE64), and at least PTHREAD_STACK_MIN in length.

For portability, pthread_attr_getguardsize() and pthread_attr_setguardsize() may modify the guardsize in the thread attribute object, but the guardsize attribute is not honored on z/OS for system-managed stack. In the case of application-managed stack, guarding is an application responsibility.

The guardsize attribute is not honored on z/OS.

When a thread is created using an attribute object with a stackaddr attribute set, behavior is undefined if the application ever accesses the same storage again, except through normal stack access in that thread. An attribute object with stackaddr attribute set may not be used more than once, unless it is destroyed and re-initialized, or its stackaddr attribute changed.