]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_detach.3
pthread_create.3: ATTRIBUTES: Note function that is thread-safe
[thirdparty/man-pages.git] / man3 / pthread_detach.3
CommitLineData
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.\"
48718eb3 26.TH PTHREAD_DETACH 3 2008-11-27 "Linux" "Linux Programmer's Manual"
b290aa63
MK
27.SH NAME
28pthread_detach \- detach a thread
29.SH SYNOPSIS
30.nf
31.B #include <pthread.h>
32
33.BI "int pthread_detach(pthread_t " thread );
34.fi
35.sp
36Compile and link with \fI\-pthread\fP.
37.SH DESCRIPTION
38The
39.BR pthread_detach ()
40function marks the thread identified by
41.IR thread
42as detached.
43When a detached thread terminates,
44its resources are automatically released back to the system without
5de8e5f9 45the need for another thread to join with the terminated thread.
b290aa63
MK
46
47Attempting to detach an already detached thread results
48in unspecified behavior.
49.SH RETURN VALUE
50On success,
51.BR pthread_detach ()
52returns 0;
53on error, it returns an error number.
54.SH ERRORS
55.TP
56.B EINVAL
57.I thread
58is not a joinable thread.
59.TP
60.B ESRCH
48718eb3
MK
61No thread with the ID
62.I thread
63could be found.
b290aa63
MK
64.SH CONFORMING TO
65POSIX.1-2001.
66.SH NOTES
67Once a thread has been detached, it can't be joined with
68.BR pthread_join (3)
69or be made joinable again.
70
71A new thread can be created in a detached state using
72.BR pthread_attr_setdetachstate (3)
73to set the detached attribute of the
74.I attr
75argument of
76.BR pthread_create (3).
77
78The detached attribute merely determines the behavior of the system
79when the thread terminates;
80it does not prevent the thread from being terminated
81if the process terminates using
82.BR exit (3)
83(or equivalently, if the main thread returns).
84
85Either
86.BR pthread_join (3)
87or
88.BR pthread_detach ()
89should be called for each thread that an application creates,
90so that system resources for the thread can be released.
91(But note that the resources of all threads are freed when the
92process terminates.)
93.SH EXAMPLE
94The following statement detaches the calling thread:
95
96 pthread_detach(pthread_self());
97.SH SEE ALSO
98.BR pthread_attr_setdetachstate (3),
99.BR pthread_cancel (3),
100.BR pthread_create (3),
101.BR pthread_exit (3),
102.BR pthread_join (3),
103.BR pthreads (7)