]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_attr_setdetachstate.3
b98896327676d97e31a95dfb7f9ece33c556504e
[thirdparty/man-pages.git] / man3 / pthread_attr_setdetachstate.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH PTHREAD_ATTR_SETDETACHSTATE 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
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 .PP
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 .PP
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 .PP
48 The default setting of the detach state attribute in a newly initialized
49 thread attributes object is
50 .BR PTHREAD_CREATE_JOINABLE .
51 .PP
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 .ad l
72 .nh
73 .TS
74 allbox;
75 lbx lb lb
76 l l l.
77 Interface Attribute Value
78 T{
79 .BR pthread_attr_setdetachstate (),
80 .BR pthread_attr_getdetachstate ()
81 T} Thread safety MT-Safe
82 .TE
83 .hy
84 .ad
85 .sp 1
86 .SH STANDARDS
87 POSIX.1-2001, POSIX.1-2008.
88 .SH NOTES
89 See
90 .BR pthread_create (3)
91 for more details on detached and joinable threads.
92 .PP
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 .PP
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)