|PTHREAD_DETACH(3P)||POSIX Programmer's Manual||PTHREAD_DETACH(3P)|
int pthread_detach(pthread_t thread);
The behavior is undefined if the value specified by the thread argument to pthread_detach() does not refer to a joinable thread.
The following sections are informative.
It has been suggested that a ``detach'' function is not necessary; the detachstate thread creation attribute is sufficient, since a thread need never be dynamically detached. However, need arises in at least two cases:
- In a cancellation handler for a pthread_join() it is nearly essential to have a pthread_detach() function in order to detach the thread on which pthread_join() was waiting. Without it, it would be necessary to have the handler do another pthread_join() to attempt to detach the thread, which would both delay the cancellation processing for an unbounded period and introduce a new call to pthread_join(), which might itself need a cancellation handler. A dynamic detach is nearly essential in this case.
- In order to detach the ``initial thread'' (as may be desirable in processes that set up server threads).
If an implementation detects that the value specified by the thread argument to pthread_detach() does not refer to a joinable thread, it is recommended that the function should fail and report an [EINVAL] error.
If an implementation detects use of a thread ID after the end of its lifetime, it is recommended that the function should fail and report an [ESRCH] error.
The Base Definitions volume of POSIX.1‐2017, <pthread.h>
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|2017||IEEE/The Open Group|