OSDN Git Service

5d398a3d752dd5dc1cd4ae6e9ea9e4f892451033
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_attr_setdetachstate.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_ATTR_SETDETACHSTATE 3 2014-05-28 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_attr_setdetachstate, pthread_attr_getdetachstate \-
29 set/get detach state attribute in thread attributes object
30 .SH SYNOPSIS
31 .nf
32 .B #include <pthread.h>
33
34 .BI "int pthread_attr_setdetachstate(pthread_attr_t *" attr \
35 ", int " detachstate );
36 .BI "int pthread_attr_getdetachstate(const pthread_attr_t *" attr \
37 ", int *" detachstate );
38 .sp
39 Compile and link with \fI\-pthread\fP.
40 .fi
41 .SH DESCRIPTION
42 The
43 .BR pthread_attr_setdetachstate ()
44 function sets the detach state attribute of the
45 thread attributes object referred to by
46 .IR attr
47 to the value specified in
48 .IR detachstate .
49 The detach state attribute determines whether a thread created using
50 the thread attributes object
51 .I attr
52 will be created in a joinable or a detached state.
53
54 The following values may be specified in
55 .IR detachstate :
56 .TP
57 .B PTHREAD_CREATE_DETACHED
58 Threads that are created using
59 .I attr
60 will be created in a detached state.
61 .TP
62 .B PTHREAD_CREATE_JOINABLE
63 Threads that are created using
64 .I attr
65 will be created in a joinable state.
66 .PP
67 The default setting of the detach state attribute in a newly initialized
68 thread attributes object is
69 .BR PTHREAD_CREATE_JOINABLE .
70
71 The
72 .BR pthread_attr_getdetachstate ()
73 returns the detach state attribute of the thread attributes object
74 .IR attr
75 in the buffer pointed to by
76 .IR detachstate .
77 .SH RETURN VALUE
78 On success, these functions return 0;
79 on error, they return a nonzero error number.
80 .SH ERRORS
81 .BR pthread_attr_setdetachstate ()
82 can fail with the following error:
83 .TP
84 .B EINVAL
85 An invalid value was specified in
86 .IR detachstate .
87 .SH ATTRIBUTES
88 .SS Multithreading (see pthreads(7))
89 The
90 .BR pthread_attr_setdetachstate ()
91 and
92 .BR pthread_attr_getdetachstate ()
93 functions are thread-safe.
94 .SH CONFORMING TO
95 POSIX.1-2001.
96 .SH NOTES
97 See
98 .BR pthread_create (3)
99 for more details on detached and joinable threads.
100
101 A thread that is created in a joinable state should
102 eventually either be joined using
103 .BR pthread_join (3)
104 or detached using
105 .BR pthread_detach (3);
106 see
107 .BR pthread_create (3).
108
109 It is an error to specify the thread ID of
110 a thread that was created in a detached state
111 in a later call to
112 .BR pthread_detach (3)
113 or
114 .BR pthread_join (3).
115 .SH EXAMPLE
116 See
117 .BR pthread_attr_init (3).
118 .SH SEE ALSO
119 .BR pthread_attr_init (3),
120 .BR pthread_create (3),
121 .BR pthread_detach (3),
122 .BR pthread_join (3),
123 .BR pthreads (7)
124 .SH COLOPHON
125 This page is part of release 3.78 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 information about reporting bugs,
130 and the latest version of this page,
131 can be found at
132 \%http://www.kernel.org/doc/man\-pages/.