title: pthread_detach doesn't change anything
body: <p>I understand pthread_detach(pid) that: &quot;storage for the thread thread can be reclaimed when that thread terminate&quot; (as per <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_detach.html" rel="nofollow noreferrer">http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_detach.html</a>)
  However, I understand that means that once the pid thread finishes executing, its memory will be freed, and we will not be able to run it again, or call join on it.
  However, I tried the following code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;
  
  void* myFunction (void* arg)
  {
    printf(&quot;Hello World from thread!\n&quot;);
  
  }
  
  int main()
  {
  pthread_t tid;
  pthread_create(&amp;tid, NULL, myFunction, NULL);
  //pthread_join(tid, NULL);
  
  int isDetached = -10;
  isDetached = pthread_detach(tid);
  printf(&quot;Is my thread detached: %d\n&quot;, isDetached);
  
  int i;
  for (i = 0; i&lt;15; i++)
      printf(&quot;%d\n&quot;, i);
  
  pthread_create(&amp;tid, NULL, myFunction, NULL);
  pthread_join(tid, NULL);
  
  for (i = 0; i&lt;15; i++)
      printf(&quot;%d\n&quot;, i);
  
  return 0;
  </code></pre>
  <p>}</p>
  <p>And I get the following:
  <a href="https://i.stack.imgur.com/GHYLk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GHYLk.png" alt="result" /></a></p>
  <p>If I understand correctly, since I did pthread_detach(tid), I should not be able to be able to do</p>
  <pre><code>pthread_create(&amp;tid, NULL, myFunction, NULL);
  pthread_join(tid, NULL);
  </code></pre>
  <p>after it, yet I did and it works perfectly. So, what is really the purpose of doing othread_detach(pid) if we can still run the thread and join it?</p>
  <p>Thanks a lot!</p>