Back to index

glibc  2.9
pthread_detach.c File Reference
#include <errno.h>
#include "pthreadP.h"
#include <atomic.h>

Go to the source code of this file.


int pthread_detach (pthread_t th)

Function Documentation

Definition at line 26 of file pthread_detach.c.

  struct pthread *pd = (struct pthread *) th;

  /* Make sure the descriptor is valid.  */
    /* Not a valid thread handle.  */
    return ESRCH;

  int result = 0;

  /* Mark the thread as detached.  */
  if (atomic_compare_and_exchange_bool_acq (&pd->joinid, pd, NULL))
      /* There are two possibilities here.  First, the thread might
        already be detached.  In this case we return EINVAL.
        Otherwise there might already be a waiter.  The standard does
        not mention what happens in this case.  */
      if (IS_DETACHED (pd))
       result = EINVAL;
    /* Check whether the thread terminated meanwhile.  In this case we
       will just free the TCB.  */
    if ((pd->cancelhandling & EXITING_BITMASK) != 0)
      /* Note that the code in __free_tcb makes sure each thread
        control block is freed only once.  */
      __free_tcb (pd);

  return result;

Here is the call graph for this function: