1PTHREAD_DETACH(3P) POSIX Programmer's Manual PTHREAD_DETACH(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 pthread_detach - detach a thread
13
15 #include <pthread.h>
16
17 int pthread_detach(pthread_t thread);
18
19
21 The pthread_detach() function shall indicate to the implementation that
22 storage for the thread thread can be reclaimed when that thread termi‐
23 nates. If thread has not terminated, pthread_detach() shall not cause
24 it to terminate. The effect of multiple pthread_detach() calls on the
25 same target thread is unspecified.
26
28 If the call succeeds, pthread_detach() shall return 0; otherwise, an
29 error number shall be returned to indicate the error.
30
32 The pthread_detach() function shall fail if:
33
34 EINVAL The implementation has detected that the value specified by
35 thread does not refer to a joinable thread.
36
37 ESRCH No thread could be found corresponding to that specified by the
38 given thread ID.
39
40
41 The pthread_detach() function shall not return an error code of
42 [EINTR].
43
44 The following sections are informative.
45
47 None.
48
50 None.
51
53 The pthread_join() or pthread_detach() functions should eventually be
54 called for every thread that is created so that storage associated with
55 the thread may be reclaimed.
56
57 It has been suggested that a "detach" function is not necessary; the
58 detachstate thread creation attribute is sufficient, since a thread
59 need never be dynamically detached. However, need arises in at least
60 two cases:
61
62 1. In a cancellation handler for a pthread_join() it is nearly essen‐
63 tial to have a pthread_detach() function in order to detach the
64 thread on which pthread_join() was waiting. Without it, it would be
65 necessary to have the handler do another pthread_join() to attempt
66 to detach the thread, which would both delay the cancellation pro‐
67 cessing for an unbounded period and introduce a new call to
68 pthread_join(), which might itself need a cancellation handler. A
69 dynamic detach is nearly essential in this case.
70
71 2. In order to detach the "initial thread" (as may be desirable in
72 processes that set up server threads).
73
75 None.
76
78 pthread_join(), the Base Definitions volume of IEEE Std 1003.1-2001,
79 <pthread.h>
80
82 Portions of this text are reprinted and reproduced in electronic form
83 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
84 -- Portable Operating System Interface (POSIX), The Open Group Base
85 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
86 Electrical and Electronics Engineers, Inc and The Open Group. In the
87 event of any discrepancy between this version and the original IEEE and
88 The Open Group Standard, the original IEEE and The Open Group Standard
89 is the referee document. The original Standard can be obtained online
90 at http://www.opengroup.org/unix/online.html .
91
92
93
94IEEE/The Open Group 2003 PTHREAD_DETACH(3P)