| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_attr_setdetachstate 3 2025-05-17 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
pthread_attr_setdetachstate, pthread_attr_getdetachstate \- |
| 9 |
set/get detach state attribute in thread attributes object |
| 10 |
.SH LIBRARY |
| 11 |
POSIX threads library |
| 12 |
.RI ( libpthread ,\~ \-lpthread ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <pthread.h> |
| 16 |
.P |
| 17 |
.BI "int pthread_attr_setdetachstate(pthread_attr_t *" attr \ |
| 18 |
", int " detachstate ); |
| 19 |
.BI "int pthread_attr_getdetachstate(const pthread_attr_t *" attr , |
| 20 |
.BI " int *" detachstate ); |
| 21 |
.fi |
| 22 |
.SH DESCRIPTION |
| 23 |
The |
| 24 |
.BR pthread_attr_setdetachstate () |
| 25 |
function sets the detach state attribute of the |
| 26 |
thread attributes object referred to by |
| 27 |
.I attr |
| 28 |
to the value specified in |
| 29 |
.IR detachstate . |
| 30 |
The detach state attribute determines whether a thread created using |
| 31 |
the thread attributes object |
| 32 |
.I attr |
| 33 |
will be created in a joinable or a detached state. |
| 34 |
.P |
| 35 |
The following values may be specified in |
| 36 |
.IR detachstate : |
| 37 |
.TP |
| 38 |
.B PTHREAD_CREATE_DETACHED |
| 39 |
Threads that are created using |
| 40 |
.I attr |
| 41 |
will be created in a detached state. |
| 42 |
.TP |
| 43 |
.B PTHREAD_CREATE_JOINABLE |
| 44 |
Threads that are created using |
| 45 |
.I attr |
| 46 |
will be created in a joinable state. |
| 47 |
.P |
| 48 |
The default setting of the detach state attribute in a newly initialized |
| 49 |
thread attributes object is |
| 50 |
.BR PTHREAD_CREATE_JOINABLE . |
| 51 |
.P |
| 52 |
The |
| 53 |
.BR pthread_attr_getdetachstate () |
| 54 |
returns the detach state attribute of the thread attributes object |
| 55 |
.I attr |
| 56 |
in the buffer pointed to by |
| 57 |
.IR detachstate . |
| 58 |
.SH RETURN VALUE |
| 59 |
On success, these functions return 0; |
| 60 |
on error, they return a nonzero error number. |
| 61 |
.SH ERRORS |
| 62 |
.BR pthread_attr_setdetachstate () |
| 63 |
can fail with the following error: |
| 64 |
.TP |
| 65 |
.B EINVAL |
| 66 |
An invalid value was specified in |
| 67 |
.IR detachstate . |
| 68 |
.SH ATTRIBUTES |
| 69 |
For an explanation of the terms used in this section, see |
| 70 |
.BR attributes (7). |
| 71 |
.TS |
| 72 |
allbox; |
| 73 |
lbx lb lb |
| 74 |
l l l. |
| 75 |
Interface Attribute Value |
| 76 |
T{ |
| 77 |
.na |
| 78 |
.nh |
| 79 |
.BR pthread_attr_setdetachstate (), |
| 80 |
.BR pthread_attr_getdetachstate () |
| 81 |
T} Thread safety MT-Safe |
| 82 |
.TE |
| 83 |
.SH STANDARDS |
| 84 |
POSIX.1-2008. |
| 85 |
.SH HISTORY |
| 86 |
POSIX.1-2001. |
| 87 |
.SH NOTES |
| 88 |
See |
| 89 |
.BR pthread_create (3) |
| 90 |
for more details on detached and joinable threads. |
| 91 |
.P |
| 92 |
A thread that is created in a joinable state should |
| 93 |
eventually either be joined using |
| 94 |
.BR pthread_join (3) |
| 95 |
or detached using |
| 96 |
.BR pthread_detach (3); |
| 97 |
see |
| 98 |
.BR pthread_create (3). |
| 99 |
.P |
| 100 |
It is an error to specify the thread ID of |
| 101 |
a thread that was created in a detached state |
| 102 |
in a later call to |
| 103 |
.BR pthread_detach (3) |
| 104 |
or |
| 105 |
.BR pthread_join (3). |
| 106 |
.SH EXAMPLES |
| 107 |
See |
| 108 |
.BR pthread_attr_init (3). |
| 109 |
.SH SEE ALSO |
| 110 |
.BR pthread_attr_init (3), |
| 111 |
.BR pthread_create (3), |
| 112 |
.BR pthread_detach (3), |
| 113 |
.BR pthread_join (3), |
| 114 |
.BR pthreads (7) |