Debian Codegraph @

upstream/debian-trixie/man3/pthread_attr_setdetachstate.3

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