2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH pthread_detach 3 (date) "Linux man-pages (unreleased)"
9 pthread_detach \- detach a thread
12 .RI ( libpthread ", " \-lpthread )
15 .B #include <pthread.h>
17 .BI "int pthread_detach(pthread_t " thread );
22 function marks the thread identified by
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.
29 Attempting to detach an already detached thread results
30 in unspecified behavior.
35 on error, it returns an error number.
40 is not a joinable thread.
47 For an explanation of the terms used in this section, see
55 Interface Attribute Value
58 T} Thread safety MT-Safe
64 POSIX.1-2001, POSIX.1-2008.
66 Once a thread has been detached, it can't be joined with
68 or be made joinable again.
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
75 .BR pthread_create (3).
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
82 (or equivalently, if the main thread returns).
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.)
93 The following statement detaches the calling thread:
97 pthread_detach(pthread_self());
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),