1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH PTHREAD_DETACH 3 2021-03-22 "Linux man-pages (unreleased)"
8 pthread_detach \- detach a thread
11 .RI ( libpthread ", " \-lpthread )
14 .B #include <pthread.h>
16 .BI "int pthread_detach(pthread_t " thread );
21 function marks the thread identified by
24 When a detached thread terminates,
25 its resources are automatically released back to the system without
26 the need for another thread to join with the terminated thread.
28 Attempting to detach an already detached thread results
29 in unspecified behavior.
34 on error, it returns an error number.
39 is not a joinable thread.
46 For an explanation of the terms used in this section, see
54 Interface Attribute Value
57 T} Thread safety MT-Safe
63 POSIX.1-2001, POSIX.1-2008.
65 Once a thread has been detached, it can't be joined with
67 or be made joinable again.
69 A new thread can be created in a detached state using
70 .BR pthread_attr_setdetachstate (3)
71 to set the detached attribute of the
74 .BR pthread_create (3).
76 The detached attribute merely determines the behavior of the system
77 when the thread terminates;
78 it does not prevent the thread from being terminated
79 if the process terminates using
81 (or equivalently, if the main thread returns).
87 should be called for each thread that an application creates,
88 so that system resources for the thread can be released.
89 (But note that the resources of any threads for which one of these
90 actions has not been done will be freed when the process terminates.)
92 The following statement detaches the calling thread:
96 pthread_detach(pthread_self());
100 .BR pthread_attr_setdetachstate (3),
101 .BR pthread_cancel (3),
102 .BR pthread_create (3),
103 .BR pthread_exit (3),
104 .BR pthread_join (3),