PTHREAD_DETACH(3)          POSIX Programmer's Manual         PTHREAD_DETACH(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       pthread_detach -- detach a thread

SSYYNNOOPPSSIISS
       #include <pthread.h>

       int pthread_detach(pthread_t _t_h_r_e_a_d);

DDEESSCCRRIIPPTTIIOONN
       The _p_t_h_r_e_a_d___d_e_t_a_c_h() function shall indicate to the implementation that
       storage for the thread _t_h_r_e_a_d can be reclaimed when that thread
       terminates. If _t_h_r_e_a_d has not terminated, _p_t_h_r_e_a_d___d_e_t_a_c_h() shall not
       cause it to terminate.

       The behavior is undefined if the value specified by the _t_h_r_e_a_d argument
       to _p_t_h_r_e_a_d___d_e_t_a_c_h() does not refer to a joinable thread.

RREETTUURRNN VVAALLUUEE
       If the call succeeds, _p_t_h_r_e_a_d___d_e_t_a_c_h() shall return 0; otherwise, an
       error number shall be returned to indicate the error.

EERRRROORRSS
       The _p_t_h_r_e_a_d___d_e_t_a_c_h() function shall not return an error code of
       [[EEIINNTTRR]].

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       The _p_t_h_r_e_a_d___j_o_i_n() or _p_t_h_r_e_a_d___d_e_t_a_c_h() functions should eventually be
       called for every thread that is created so that storage associated with
       the thread may be reclaimed.

       It has been suggested that a ``detach'' function is not necessary; the
       _d_e_t_a_c_h_s_t_a_t_e thread creation attribute is sufficient, since a thread
       need never be dynamically detached. However, need arises in at least
       two cases:

        1. In a cancellation handler for a _p_t_h_r_e_a_d___j_o_i_n() it is nearly
           essential to have a _p_t_h_r_e_a_d___d_e_t_a_c_h() function in order to detach
           the thread on which _p_t_h_r_e_a_d___j_o_i_n() was waiting. Without it, it
           would be necessary to have the handler do another _p_t_h_r_e_a_d___j_o_i_n() to
           attempt to detach the thread, which would both delay the
           cancellation processing for an unbounded period and introduce a new
           call to _p_t_h_r_e_a_d___j_o_i_n(), which might itself need a cancellation
           handler. A dynamic detach is nearly essential in this case.

        2. 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 _t_h_r_e_a_d
       argument to _p_t_h_r_e_a_d___d_e_t_a_c_h() does not refer to a joinable thread, it is
       recommended that the function should fail and report an [[EEIINNVVAALL]] 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
       [[EESSRRCCHH]] error.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _p_t_h_r_e_a_d___j_o_i_n()

       The Base Definitions volume of POSIX.1-2017, <<pptthhrreeaadd..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       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 .



IEEE/The Open Group                  2017                    PTHREAD_DETACH(3)
