Name
      
      pthread_detach 
      
      
      - detach a thread
      
      
      
      
         
         Library
      
      
      
      
      libc_r.lib
      
      
      libpthread.lib
      
      
      libthr.lib
      
      
      
      
         
         Synopsis
      
      
      
      
      
      
      
         
            |   | 
            
                int
               
               
               pthread_detach (pthread_t thrHandle); 
               
               
               
               
               
               
             | 
         
      
      
         
         Return values
      
      
      If successful, the
      
      
       pthread_detach
      function will return zero.
      Otherwise an error number will be returned to
      indicate the error.
      
      
      
      
         
         Detailed description
      
      
      The
      
      
       pthread_detach
      function is used to indicate to the implementation that storage for the
      thread
      
      
       thrHandle
      can be reclaimed when the thread terminates.
      If
      
      
       thrHandle
      has not terminated,
      
      
       pthread_detach
      will not cause it to terminate.
      The effect of multiple
      
      
       pthread_detach
      calls on the same target thread is unspecified.
      
      
      
      
         
         Examples
      
      
      
      
      void *a_thread_func_1_1(void*)
{
 sleep(10);
 return NULL;
}
int main_1_1()
{
 pthread_attr_t new_attr;
 pthread_t new_th;
 int ret;
 /* Initialize attribute */
 if(pthread_attr_init(&new_attr) != 0)
 {
  perror("Cannot initialize attribute object\n");
  return -1;
 }
 /* Set the attribute object to be joinable */
 if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0)
 {
  perror("Error in pthread_attr_setdetachstate()\n");
  return -1;
 }
 /* Create the thread */
 if(pthread_create(&new_th, &new_attr, a_thread_func_1_1, NULL) != 0)
 {
  perror("Error creating thread\n");
  return -1;
 }
 /* Detach the thread. */
 if(pthread_detach(new_th) != 0)
 {
  printf("Error detaching thread\n");
  return -1;
 }
         
      
         
         Errors
      
      
      The
      
      
       pthread_detach
      function will fail if:
      
      
      
      
      
      
         
            | [EINVAL]
               
             | 
         
         
            |   | 
            
               The implementation has detected that the value specified by
               
               
                thrHandle
               does not refer to a joinable thread. or if someother thread has already joined
               
               
               
             | 
         
         
            | [ESRCH]
               
             | 
         
         
            |   | 
            
               No thread could be found corresponding to that specified by the given
               thread ID,
               
               
                thrHandle.
               
               
               
             | 
         
         
      
      
      
      
         
         See also
      
      
      
      
      pthread_join
      
      
         
      
      
      Feedback
For additional information or queries on this page send feedback	
      
      
         
         
         
            
               | 
                   © 2005-2007 Nokia  
                | 
                
                     
                |