Open System Services System Calls Reference Manual (G06.28+)
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
H-series OSS processes: /G/system/zdllnnn/zsptdll
SYNOPSIS
#include <spthread.h>
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.
RETURN VALUES
If an error condition occurs, this function returns an integer value indicating the type of error.
Possible return values are:
0 Successful completion.
[EINVAL] The value specified by the attr parameter is not a valid thread attributes object or
the detachstate parameter is invalid.
5−28 Hewlett-Packard Company 527186-005