Use pthread_attr_init(3THR) to initialize object attributes to their default values. The storage is allocated by the thread system during execution.
Prototype: int pthread_attr_init(pthread_attr_t *tattr);
#include <pthread.h> pthread_attr_t tattr; int ret; /* initialize an attribute to the default value */ ret = pthread_attr_init(&tattr);
Table 3–1 shows the default values for attributes (tattr) .
Table 3–1 Default Attribute Values for tattr
Attribute |
Value |
Result |
---|---|---|
scope |
PTHREAD_SCOPE_PROCESS |
New thread is unbound – not permanently attached to LWP. |
detachstate |
PTHREAD_CREATE_JOINABLE |
Exit status and thread are preserved after the thread terminates. |
stackaddr |
NULL |
New thread has system-allocated stack address. |
stacksize |
0 |
New thread has system-defined stack size. |
priority |
0 |
New thread has priority 0. |
inheritsched |
PTHREAD_EXPLICIT_SCHED |
New thread does not inherit parent thread scheduling priority. |
schedpolicy |
SCHED_OTHER |
New thread uses Solaris-defined fixed priorities for synchronization object contention; threads run until preempted or until they block or yield. |
pthread_attr_init() returns zero after completing successfully. Any other return value indicates that an error occurred. If the following condition occurs, the function fails and returns the corresponding value.
ENOMEM
Returned when there is not enough memory to initialize the thread attributes object.