]>
Commit | Line | Data |
---|---|---|
b290aa63 MK |
1 | .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
2 | .\" <mtk.manpages@gmail.com> | |
3 | .\" | |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
b290aa63 MK |
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. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
b290aa63 | 25 | .\" |
4b8c67d9 | 26 | .TH PTHREAD_DETACH 3 2017-09-15 "Linux" "Linux Programmer's Manual" |
b290aa63 MK |
27 | .SH NAME |
28 | pthread_detach \- detach a thread | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <pthread.h> | |
dbfe9c70 | 32 | .PP |
b290aa63 MK |
33 | .BI "int pthread_detach(pthread_t " thread ); |
34 | .fi | |
68e4db0a | 35 | .PP |
b290aa63 MK |
36 | Compile and link with \fI\-pthread\fP. |
37 | .SH DESCRIPTION | |
38 | The | |
39 | .BR pthread_detach () | |
40 | function marks the thread identified by | |
41 | .IR thread | |
42 | as detached. | |
43 | When a detached thread terminates, | |
44 | its resources are automatically released back to the system without | |
5de8e5f9 | 45 | the need for another thread to join with the terminated thread. |
847e0d88 | 46 | .PP |
b290aa63 MK |
47 | Attempting to detach an already detached thread results |
48 | in unspecified behavior. | |
49 | .SH RETURN VALUE | |
50 | On success, | |
51 | .BR pthread_detach () | |
52 | returns 0; | |
53 | on error, it returns an error number. | |
54 | .SH ERRORS | |
55 | .TP | |
56 | .B EINVAL | |
57 | .I thread | |
58 | is not a joinable thread. | |
59 | .TP | |
60 | .B ESRCH | |
48718eb3 MK |
61 | No thread with the ID |
62 | .I thread | |
63 | could be found. | |
bf0fbbcd ZL |
64 | .SH ATTRIBUTES |
65 | For an explanation of the terms used in this section, see | |
66 | .BR attributes (7). | |
67 | .TS | |
68 | allbox; | |
69 | lb lb lb | |
70 | l l l. | |
71 | Interface Attribute Value | |
72 | T{ | |
73 | .BR pthread_detach () | |
74 | T} Thread safety MT-Safe | |
75 | .TE | |
847e0d88 | 76 | .sp 1 |
b290aa63 | 77 | .SH CONFORMING TO |
6f02b44c | 78 | POSIX.1-2001, POSIX.1-2008. |
b290aa63 MK |
79 | .SH NOTES |
80 | Once a thread has been detached, it can't be joined with | |
81 | .BR pthread_join (3) | |
82 | or be made joinable again. | |
847e0d88 | 83 | .PP |
b290aa63 MK |
84 | A new thread can be created in a detached state using |
85 | .BR pthread_attr_setdetachstate (3) | |
86 | to set the detached attribute of the | |
87 | .I attr | |
88 | argument of | |
89 | .BR pthread_create (3). | |
847e0d88 | 90 | .PP |
b290aa63 MK |
91 | The detached attribute merely determines the behavior of the system |
92 | when the thread terminates; | |
93 | it does not prevent the thread from being terminated | |
94 | if the process terminates using | |
95 | .BR exit (3) | |
96 | (or equivalently, if the main thread returns). | |
847e0d88 | 97 | .PP |
b290aa63 MK |
98 | Either |
99 | .BR pthread_join (3) | |
100 | or | |
101 | .BR pthread_detach () | |
102 | should be called for each thread that an application creates, | |
103 | so that system resources for the thread can be released. | |
76f23c94 MK |
104 | (But note that the resources of any threads for which one of these |
105 | actions has not been done will be freed when the process terminates.) | |
b290aa63 MK |
106 | .SH EXAMPLE |
107 | The following statement detaches the calling thread: | |
847e0d88 | 108 | .PP |
b290aa63 MK |
109 | pthread_detach(pthread_self()); |
110 | .SH SEE ALSO | |
111 | .BR pthread_attr_setdetachstate (3), | |
112 | .BR pthread_cancel (3), | |
113 | .BR pthread_create (3), | |
114 | .BR pthread_exit (3), | |
115 | .BR pthread_join (3), | |
116 | .BR pthreads (7) |