Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

System Functions (n - p) pthread_attr_setguardsize(2)
NAME
pthread_attr_setguardsize - Sets the guardsize attribute of a thread attributes object
LIBRARY
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/yputdll
SYNOPSIS
#include <pthread.h>
int pthread_attr_setguardsize(
pthread_attr_t *attr,
size_t guardsize);
PARAMETERS
attr Specifies the address of the thread attributes object whose guardsize attribute is
to be set.
guardsize Specifies the new value for the guardsize attribute.
DESCRIPTION
The pthread_attr_setguardsize function sets the value of the guardsize attribute of the thread
attributes object specified by the attr parameter to the value specified by the guardsize parameter.
When the protected stack feature is enabled and the guard size is 0 (zero), a regular stack is
created without a guard page the next time the pthread_create function is called for the attri-
butes object.
When the protected stack feature is enabled, the value of the guard size is rounded up to a multi-
ple of a page size.
When creating a thread, use a thread attributes object to specify nondefault values for thread
attributes. The guardsize attribute of a thread attributes object specifies the minimum size (in
bytes) of the guard area for the stack of a new thread.
A guard area can help a multi-threaded program detect overflow of a thread’s stack. A guard
area is a region of no-access memory that the system allocates at the overflow end of the thread’s
stack. When any thread attempts to access a memory location within this region, a memory
addressing violation occurs.
A new thread can be created with the default value for the guardsize attribute. This value is
platform-dependent but is always at least one "hardware protection unit" (that is, at least one
page).
After this function is called, the system might reserve a larger guard area for a new thread than
was specified by the guardsize parameter.
The system allows your program to specify the size of a thread stack’s guard area because:
When a thread allocates large data structures on its stack, a guard area with a size greater
than the default size might be required to detect stack overflow.
Overflow protection of a thread’s stack can potentially waste system resources, such as
for an application that creates a large number of threads that will never overflow their
stacks. A multi-threaded program can conserve system resources by specifying a guard-
size parameter of 0 (zero).
To use this function in a threaded application that uses the POSIX User Thread Model library on
systems running H06.21 or later RVUs or J06.10 or later RVUs, you must perform all of the fol-
lowing tasks:
527186-023 Hewlett-Packard Company 557