# pthread_attr_getdetachstate

## PROLOG



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


## NAME



           pthread_attr_getdetachstate, pthread_attr_setdetachstate — get and
           set the detachstate attribute
    


## SYNOPSIS



           #include <pthread.h>
    
           int pthread_attr_getdetachstate(const pthread_attr_t *_attr_ ,
               int *_detachstate_);
           int pthread_attr_setdetachstate(pthread_attr_t *_attr_ , int _detachstate_);
    


## DESCRIPTION



           The  _detachstate_  attribute controls whether the thread is created
           in a detached state.  If the thread is created detached, then  use
           of  the  ID of the newly created thread by the _pthread_detach_() or
           _pthread_join_() function is an error.
    
           The               _pthread_attr_getdetachstate_()                and
           _pthread_attr_setdetachstate_()  functions,  respectively, shall get
           and set the _detachstate_ attribute in the _attr_ object.
    
           For _pthread_attr_getdetachstate_(), _detachstate_  shall  be  set  to
           either PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE.
    
           For   _pthread_attr_setdetachstate_(),  the  application  shall  set
           _detachstate_     to     either      PTHREAD_CREATE_DETACHED      or
           PTHREAD_CREATE_JOINABLE.
    
           A value of PTHREAD_CREATE_DETACHED shall cause all threads created
           with  _attr_  to  be in the detached state, whereas using a value of
           PTHREAD_CREATE_JOINABLE shall cause all threads created with  _attr_
           to  be in the joinable state. The default value of the _detachstate_
           attribute shall be PTHREAD_CREATE_JOINABLE.
    
           The behavior is undefined if  the  value  specified  by  the  _attr_
           argument         to        _pthread_attr_getdetachstate_()        or
           _pthread_attr_setdetachstate_() does not  refer  to  an  initialized
           thread attributes object.
    


## RETURN VALUE



           Upon   successful  completion,  _pthread_attr_getdetachstate_()  and
           _pthread_attr_setdetachstate_()  shall  return   a   value   of   0;
           otherwise,  an  error  number  shall  be  returned to indicate the
           error.
    
           The _pthread_attr_getdetachstate_() function stores the value of the
           _detachstate_ attribute in _detachstate_ if successful.
    


## ERRORS



           The _pthread_attr_setdetachstate_() function shall fail if:
    
           **EINVAL** The value of _detachstate_ was not valid
    
           These functions shall not return an error code of **[EINTR]**.
    
           _The following sections are informative._
    


## EXAMPLES



       **Retrieving the detachstate Attribute**
           This example shows how to obtain the _detachstate_ attribute of a
           thread attribute object.
    
               #include <pthread.h>
    
               pthread_attr_t thread_attr;
               int            detachstate;
               int            rc;
    
               /* code initializing thread_attr */
               ...
    
               rc = pthread_attr_getdetachstate (&thread_attr, &detachstate);
               if (rc!=0) {
                   /* handle error */
                   ...
               }
               else {
                   /* legal values for detachstate are:
                    * PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE
                    */
                    ...
               }
    


## APPLICATION USAGE



           None.
    


## RATIONALE



           If an implementation detects that the value specified by the _attr_
           argument to _pthread_attr_getdetachstate_() or
           _pthread_attr_setdetachstate_() does not refer to an initialized
           thread attributes object, it is recommended that the function
           should fail and report an **[EINVAL]** error.
    


## FUTURE DIRECTIONS



           None.
    


* * *