1PTHREAD_DETACH(3P)         POSIX Programmer's Manual        PTHREAD_DETACH(3P)
2
3
4

PROLOG

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
11

NAME

13       pthread_detach — detach a thread
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_detach(pthread_t thread);
19

DESCRIPTION

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.
25
26       The behavior is undefined if the value specified by the thread argument
27       to pthread_detach() does not refer to a joinable thread.
28

RETURN VALUE

30       If the call succeeds, pthread_detach() shall return  0;  otherwise,  an
31       error number shall be returned to indicate the error.
32

ERRORS

34       The  pthread_detach()  function  shall  not  return  an  error  code of
35       [EINTR].
36
37       The following sections are informative.
38

EXAMPLES

40       None.
41

APPLICATION USAGE

43       None.
44

RATIONALE

46       The pthread_join() or pthread_detach() functions should  eventually  be
47       called for every thread that is created so that storage associated with
48       the thread may be reclaimed.
49
50       It has been suggested that a ``detach'' function is not necessary;  the
51       detachstate  thread  creation  attribute  is sufficient, since a thread
52       need never be dynamically detached. However, need arises  in  at  least
53       two cases:
54
55        1. In  a cancellation handler for a pthread_join() it is nearly essen‐
56           tial to have a pthread_detach() function in  order  to  detach  the
57           thread on which pthread_join() was waiting. Without it, it would be
58           necessary to have the handler do another pthread_join() to  attempt
59           to  detach the thread, which would both delay the cancellation pro‐
60           cessing for an  unbounded  period  and  introduce  a  new  call  to
61           pthread_join(),  which  might itself need a cancellation handler. A
62           dynamic detach is nearly essential in this case.
63
64        2. In order to detach the ``initial thread'' (as may be  desirable  in
65           processes that set up server threads).
66
67       If  an  implementation  detects  that the value specified by the thread
68       argument to pthread_detach() does not refer to a joinable thread, it is
69       recommended that the function should fail and report an [EINVAL] error.
70
71       If  an  implementation  detects use of a thread ID after the end of its
72       lifetime, it is recommended that the function should fail and report an
73       [ESRCH] error.
74

FUTURE DIRECTIONS

76       None.
77

SEE ALSO

79       pthread_join()
80
81       The Base Definitions volume of POSIX.1‐2008, <pthread.h>
82
84       Portions  of  this text are reprinted and reproduced in electronic form
85       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
86       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
87       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
88       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
89       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
90       event of any discrepancy between this version and the original IEEE and
91       The Open Group Standard, the original IEEE and The Open Group  Standard
92       is  the  referee document. The original Standard can be obtained online
93       at http://www.unix.org/online.html .
94
95       Any typographical or formatting errors that appear  in  this  page  are
96       most likely to have been introduced during the conversion of the source
97       files to man page format. To report such errors,  see  https://www.ker
98       nel.org/doc/man-pages/reporting_bugs.html .
99
100
101
102IEEE/The Open Group                  2013                   PTHREAD_DETACH(3P)
Impressum