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

pthread_attr_setdetachstate(2) OSS System Calls Reference Manual
NAME
pthread_attr_setdetachstate - Sets the detachstate attribute of a thread attributes object
LIBRARY
G-series native OSS processes: /G/system/sysnn/zsptsrl
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
H-series and J-series OSS processes that use the Standard POSIX Threads library:
/G/system/zdllnnn/zsptdll
SYNOPSIS
#include <pthread.h> | #include <spthread.h>
/* pthread.h is required to use POSIX User Thread Model library */
/* spthread.h is required to use Standard POSIX Threads library */
int pthread_attr_setdetachstate(
pthread_attr_t *attr,
int detachstate);
PARAMETERS
attr Specifies the thread attributes object whose detachstate attribute is to be set.
detachstate Specifies the new value for the detachstate attribute. Valid values are:
PTHREAD_CREATE_JOINABLE
This is the default value. Threads are created in "undetached"
state.
PTHREAD_CREATE_DETACHED
A created thread is detached immediately, before it begins run-
ning.
DESCRIPTION
This function sets the value of the detachstate attribute of the thread attributes object specified
by the attr parameter to the value specified by the detachstate parameter. The detachstate attri-
bute specifies whether storage used by the thread can be reclaimed by the system when the thread
terminates.
You cannot use the thread identifier (the value of type pthread_t that is returned by the
pthread_create() function) for a thread that is created detached in calls to the
pthread_detach() or pthread_join( ) functions.
When a thread that has not been detached finishes executing, the system retains the state of that
thread to allow another thread to join with it. If the thread is detached before it finishes execut-
ing, the system can immediately reclaim the thread’s storage and resources when the thread ter-
minates (that is, when it returns from its start routine, calls the pthread_exit() function, or is can-
celed.)
The pthread_join() or pthread_detach( ) function should eventually be called for every thread
that is created with the detachstate attribute of its thread attributes object set to
PTHREAD_CREATE_JOINABLE, so that storage associated with the thread can be
reclaimed.
On systems running H06.21 or later H-series RVUs or J06.10 or later J-series RVUs, you can use
either the POSIX User Thread Model library or the Standard POSIX Threads library for threaded
applications.
554 Hewlett-Packard Company 527186-023