]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_detach.3
pthread_join.3: SEE ALSO: Add pthread_tryjoin_np(3)
[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.\"
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
12.\"
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\"
24.TH PTHREAD_DETACH 3 2008-10-24 "Linux" "Linux Programmer's Manual"
25.SH NAME
26pthread_detach \- detach a thread
27.SH SYNOPSIS
28.nf
29.B #include <pthread.h>
30
31.BI "int pthread_detach(pthread_t " thread );
32.fi
33.sp
34Compile and link with \fI\-pthread\fP.
35.SH DESCRIPTION
36The
37.BR pthread_detach ()
38function marks the thread identified by
39.IR thread
40as detached.
41When a detached thread terminates,
42its resources are automatically released back to the system without
43the need for another thread to join with the terminated the thread.
44
45Attempting to detach an already detached thread results
46in unspecified behavior.
47.SH RETURN VALUE
48On success,
49.BR pthread_detach ()
50returns 0;
51on error, it returns an error number.
52.SH ERRORS
53.TP
54.B EINVAL
55.I thread
56is not a joinable thread.
57.TP
58.B ESRCH
59No thread could be found with the given thread ID.
60.SH CONFORMING TO
61POSIX.1-2001.
62.SH NOTES
63Once a thread has been detached, it can't be joined with
64.BR pthread_join (3)
65or be made joinable again.
66
67A new thread can be created in a detached state using
68.BR pthread_attr_setdetachstate (3)
69to set the detached attribute of the
70.I attr
71argument of
72.BR pthread_create (3).
73
74The detached attribute merely determines the behavior of the system
75when the thread terminates;
76it does not prevent the thread from being terminated
77if the process terminates using
78.BR exit (3)
79(or equivalently, if the main thread returns).
80
81Either
82.BR pthread_join (3)
83or
84.BR pthread_detach ()
85should be called for each thread that an application creates,
86so that system resources for the thread can be released.
87(But note that the resources of all threads are freed when the
88process terminates.)
89.SH EXAMPLE
90The following statement detaches the calling thread:
91
92 pthread_detach(pthread_self());
93.SH SEE ALSO
94.BR pthread_attr_setdetachstate (3),
95.BR pthread_cancel (3),
96.BR pthread_create (3),
97.BR pthread_exit (3),
98.BR pthread_join (3),
99.BR pthreads (7)