tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / pthread_detach.3
blob3ccce10b58f58f052b01ba34b88010118a6e15bc
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_detach 3 (date) "Linux man-pages (unreleased)"
8 .SH NAME
9 pthread_detach \- detach a thread
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_detach(pthread_t " thread );
18 .fi
19 .SH DESCRIPTION
20 The
21 .BR pthread_detach ()
22 function marks the thread identified by
23 .I thread
24 as detached.
25 When a detached thread terminates,
26 its resources are automatically released back to the system without
27 the need for another thread to join with the terminated thread.
28 .PP
29 Attempting to detach an already detached thread results
30 in unspecified behavior.
31 .SH RETURN VALUE
32 On success,
33 .BR pthread_detach ()
34 returns 0;
35 on error, it returns an error number.
36 .SH ERRORS
37 .TP
38 .B EINVAL
39 .I thread
40 is not a joinable thread.
41 .TP
42 .B ESRCH
43 No thread with the ID
44 .I thread
45 could be found.
46 .SH ATTRIBUTES
47 For an explanation of the terms used in this section, see
48 .BR attributes (7).
49 .ad l
50 .nh
51 .TS
52 allbox;
53 lbx lb lb
54 l l l.
55 Interface       Attribute       Value
57 .BR pthread_detach ()
58 T}      Thread safety   MT-Safe
59 .TE
60 .hy
61 .ad
62 .sp 1
63 .SH STANDARDS
64 POSIX.1-2001, POSIX.1-2008.
65 .SH NOTES
66 Once a thread has been detached, it can't be joined with
67 .BR pthread_join (3)
68 or be made joinable again.
69 .PP
70 A new thread can be created in a detached state using
71 .BR pthread_attr_setdetachstate (3)
72 to set the detached attribute of the
73 .I attr
74 argument of
75 .BR pthread_create (3).
76 .PP
77 The detached attribute merely determines the behavior of the system
78 when the thread terminates;
79 it does not prevent the thread from being terminated
80 if the process terminates using
81 .BR exit (3)
82 (or equivalently, if the main thread returns).
83 .PP
84 Either
85 .BR pthread_join (3)
87 .BR pthread_detach ()
88 should be called for each thread that an application creates,
89 so that system resources for the thread can be released.
90 (But note that the resources of any threads for which one of these
91 actions has not been done will be freed when the process terminates.)
92 .SH EXAMPLES
93 The following statement detaches the calling thread:
94 .PP
95 .in +4n
96 .EX
97 pthread_detach(pthread_self());
98 .EE
99 .in
100 .SH SEE ALSO
101 .BR pthread_attr_setdetachstate (3),
102 .BR pthread_cancel (3),
103 .BR pthread_create (3),
104 .BR pthread_exit (3),
105 .BR pthread_join (3),
106 .BR pthreads (7)