Multithreaded Programming Guide

Exit Print View

Updated: July 2014
 
 

Initializing Attributes

Use pthread_attr_init(3C) to initialize object attributes to their default values. The storage is allocated by the thread system during execution.

pthread_attr_init Syntax

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 contends with other threads in the process.
detachstate
PTHREAD_CREATE_JOINABLE
Completion status and thread ID are preserved after the thread exits.
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 the traditional Oracle Solaris time-sharing (TS) scheduling class.
guardsize
PAGESIZE
Stack overflow protection.

Note - The default value for the inheritsched attribute might change from PTHREAD_EXPLICIT_SCHED to PTHREAD_INHERIT_SCHED in a future Oracle Solaris release. You should call pthread_attr_setinheritsched() to set the inheritsched attribute to the value you want rather than accepting the default, in order to avoid any potential problems caused by this change.

pthread_attr_init Return Values

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

Description: Returned when not enough memory is allocated to initialize the thread attributes object.