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

NAME

12       pthread_detach — detach a thread
13

SYNOPSIS

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

DESCRIPTION

20       The pthread_detach() function shall indicate to the implementation that
21       storage  for the thread thread can be reclaimed when that thread termi‐
22       nates. If thread has not terminated, pthread_detach() shall  not  cause
23       it to terminate.
24
25       The behavior is undefined if the value specified by the thread argument
26       to pthread_detach() does not refer to a joinable thread.
27

RETURN VALUE

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

ERRORS

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

EXAMPLES

39       None.
40

APPLICATION USAGE

42       None.
43

RATIONALE

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

FUTURE DIRECTIONS

75       None.
76

SEE ALSO

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