1PTHREAD_ATTR_SETDETACHSTATE(L3i)nux Programmer's ManPuTaHlREAD_ATTR_SETDETACHSTATE(3)
2
3
4
6 pthread_attr_setdetachstate, pthread_attr_getdetachstate - set/get de‐
7 tach state attribute in thread attributes object
8
10 #include <pthread.h>
11
12 int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
13 int pthread_attr_getdetachstate(const pthread_attr_t *attr,
14 int *detachstate);
15
16 Compile and link with -pthread.
17
19 The pthread_attr_setdetachstate() function sets the detach state attri‐
20 bute of the thread attributes object referred to by attr to the value
21 specified in detachstate. The detach state attribute determines
22 whether a thread created using the thread attributes object attr will
23 be created in a joinable or a detached state.
24
25 The following values may be specified in detachstate:
26
27 PTHREAD_CREATE_DETACHED
28 Threads that are created using attr will be created in a de‐
29 tached state.
30
31 PTHREAD_CREATE_JOINABLE
32 Threads that are created using attr will be created in a join‐
33 able state.
34
35 The default setting of the detach state attribute in a newly initial‐
36 ized thread attributes object is PTHREAD_CREATE_JOINABLE.
37
38 The pthread_attr_getdetachstate() returns the detach state attribute of
39 the thread attributes object attr in the buffer pointed to by detach‐
40 state.
41
43 On success, these functions return 0; on error, they return a nonzero
44 error number.
45
47 pthread_attr_setdetachstate() can fail with the following error:
48
49 EINVAL An invalid value was specified in detachstate.
50
52 For an explanation of the terms used in this section, see at‐
53 tributes(7).
54
55 ┌────────────────────────────────────────────┬───────────────┬─────────┐
56 │Interface │ Attribute │ Value │
57 ├────────────────────────────────────────────┼───────────────┼─────────┤
58 │pthread_attr_setdetachstate(), │ Thread safety │ MT-Safe │
59 │pthread_attr_getdetachstate() │ │ │
60 └────────────────────────────────────────────┴───────────────┴─────────┘
61
63 POSIX.1-2001, POSIX.1-2008.
64
66 See pthread_create(3) for more details on detached and joinable
67 threads.
68
69 A thread that is created in a joinable state should eventually either
70 be joined using pthread_join(3) or detached using pthread_detach(3);
71 see pthread_create(3).
72
73 It is an error to specify the thread ID of a thread that was created in
74 a detached state in a later call to pthread_detach(3) or
75 pthread_join(3).
76
78 See pthread_attr_init(3).
79
81 pthread_attr_init(3), pthread_create(3), pthread_detach(3),
82 pthread_join(3), pthreads(7)
83
85 This page is part of release 5.13 of the Linux man-pages project. A
86 description of the project, information about reporting bugs, and the
87 latest version of this page, can be found at
88 https://www.kernel.org/doc/man-pages/.
89
90
91
92Linux 2021-03-22 PTHREAD_ATTR_SETDETACHSTATE(3)