title: Pthread create as detached
body: <p>I have a problem creating a thread as detached. Here's the code I wrote:</p>
  
  <pre><code>void* testFunction() {
  
      pthread_attr_t attr;
      int chk,rc;
  
  pthread_attr_init(&amp;attr);
  printf("thread_attr_init: %d\n",rc);
  
  pthread_attr_getdetachstate(&amp;attr, &amp;chk);
  printf("thread_attr_getdetachedstate: %d\n",rc);
  
  if(chk == PTHREAD_CREATE_DETACHED ) 
      printf("Detached\n");
  else if (chk == PTHREAD_CREATE_JOINABLE) 
      printf("Joinable\n");
  
  return NULL;
  }
  
  
  int main (int argc, const char * argv[]) {
  
  pthread_t thread1;
  pthread_attr_t attr;
  
  int rc;
  
  rc = pthread_attr_init(&amp;attr);
  
  printf("attr_init: %d\n",rc);
  rc = pthread_attr_setdetachstate(&amp;attr, PTHREAD_CREATE_DETACHED);
  printf("attr_setdetachedstate: %d\n",rc);
  
  rc = pthread_create(&amp;thread1, &amp;attr, testFunction, NULL);
  printf("attr_create: %d\n",rc);
  
  sleep(4);
  pthread_cancel(thread1);
  
  return 0;
  }
  </code></pre>
  
  <p>The problem is that <code>testFunction()</code> always print "Joinable". Can anyone tell me where I'm getting wrong?</p>