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

NAME

6       pthread_detach - detach a thread
7

SYNOPSIS

9       #include <pthread.h>
10
11       int pthread_detach(pthread_t thread);
12
13

DESCRIPTION

15       The pthread_detach() function shall indicate to the implementation that
16       storage for the thread thread can be reclaimed when that thread  termi‐
17       nates.  If  thread has not terminated, pthread_detach() shall not cause
18       it to terminate. The effect of multiple pthread_detach() calls  on  the
19       same target thread is unspecified.
20

RETURN VALUE

22       If  the  call  succeeds, pthread_detach() shall return 0; otherwise, an
23       error number shall be returned to indicate the error.
24

ERRORS

26       The pthread_detach() function shall fail if:
27
28       EINVAL The implementation has detected  that  the  value  specified  by
29              thread does not refer to a joinable thread.
30
31       ESRCH  No  thread could be found corresponding to that specified by the
32              given thread ID.
33
34
35       The pthread_detach()  function  shall  not  return  an  error  code  of
36       [EINTR].
37
38       The following sections are informative.
39

EXAMPLES

41       None.
42

APPLICATION USAGE

44       None.
45

RATIONALE

47       The  pthread_join()  or pthread_detach() functions should eventually be
48       called for every thread that is created so that storage associated with
49       the thread may be reclaimed.
50
51       It  has  been  suggested that a "detach" function is not necessary; the
52       detachstate thread creation attribute is  sufficient,  since  a  thread
53       need  never  be  dynamically detached. However, need arises in at least
54       two cases:
55
56        1. In a cancellation handler for a pthread_join() it is nearly  essen‐
57           tial  to  have  a  pthread_detach() function in order to detach the
58           thread on which pthread_join() was waiting. Without it, it would be
59           necessary  to have the handler do another pthread_join() to attempt
60           to detach the thread, which would both delay the cancellation  pro‐
61           cessing  for  an  unbounded  period  and  introduce  a  new call to
62           pthread_join(), which might itself need a cancellation  handler.  A
63           dynamic detach is nearly essential in this case.
64
65        2. In  order  to  detach  the "initial thread" (as may be desirable in
66           processes that set up server threads).
67

FUTURE DIRECTIONS

69       None.
70

SEE ALSO

72       pthread_join() , the Base Definitions volume  of  IEEE Std 1003.1-2001,
73       <pthread.h>
74
76       Portions  of  this text are reprinted and reproduced in electronic form
77       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
78       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
79       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
80       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
81       event of any discrepancy between this version and the original IEEE and
82       The  Open Group Standard, the original IEEE and The Open Group Standard
83       is the referee document. The original Standard can be  obtained  online
84       at http://www.opengroup.org/unix/online.html .
85
86
87
88IEEE/The Open Group                  2003                    PTHREAD_DETACH(P)
Impressum