1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH PTHREAD_ATTR_SETDETACHSTATE 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
8 pthread_attr_setdetachstate, pthread_attr_getdetachstate \-
9 set/get detach state attribute in thread attributes object
12 .RI ( libpthread ", " \-lpthread )
15 .B #include <pthread.h>
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 );
24 .BR pthread_attr_setdetachstate ()
25 function sets the detach state attribute of the
26 thread attributes object referred to by
28 to the value specified in
30 The detach state attribute determines whether a thread created using
31 the thread attributes object
33 will be created in a joinable or a detached state.
35 The following values may be specified in
38 .B PTHREAD_CREATE_DETACHED
39 Threads that are created using
41 will be created in a detached state.
43 .B PTHREAD_CREATE_JOINABLE
44 Threads that are created using
46 will be created in a joinable state.
48 The default setting of the detach state attribute in a newly initialized
49 thread attributes object is
50 .BR PTHREAD_CREATE_JOINABLE .
53 .BR pthread_attr_getdetachstate ()
54 returns the detach state attribute of the thread attributes object
56 in the buffer pointed to by
59 On success, these functions return 0;
60 on error, they return a nonzero error number.
62 .BR pthread_attr_setdetachstate ()
63 can fail with the following error:
66 An invalid value was specified in
69 For an explanation of the terms used in this section, see
77 Interface Attribute Value
79 .BR pthread_attr_setdetachstate (),
80 .BR pthread_attr_getdetachstate ()
81 T} Thread safety MT-Safe
87 POSIX.1-2001, POSIX.1-2008.
90 .BR pthread_create (3)
91 for more details on detached and joinable threads.
93 A thread that is created in a joinable state should
94 eventually either be joined using
97 .BR pthread_detach (3);
99 .BR pthread_create (3).
101 It is an error to specify the thread ID of
102 a thread that was created in a detached state
104 .BR pthread_detach (3)
106 .BR pthread_join (3).
109 .BR pthread_attr_init (3).
111 .BR pthread_attr_init (3),
112 .BR pthread_create (3),
113 .BR pthread_detach (3),
114 .BR pthread_join (3),