title: pthread_join function kill the thread after execution or we need to call pthread_cancel/pthread_exit?
body: <p><code>pthread_join()</code> function kill the thread after execution or we need to call <code>pthread_cancel()</code>/<code>pthread_exit()</code>?</p>
  
  <p>I am calling <code>pthread_cancel()</code>/<code>pthread_kill()</code> which is returning 3 ie no thread attached with thread_id.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  
  void * run (void *);
  
  int main() {
  pthread_t p1, p2;
  int a = 9;
  printf("%d\n", pthread_create(&amp;p1, NULL, &amp;run, (void*)&amp;p1));
  printf("%d\n", pthread_create(&amp;p2, NULL, &amp;run, (void*)&amp;p2));
  
  printf("%d\n", pthread_join(p1, NULL));
  //usleep(1000);
  printf("%d\n", pthread_join(p2, NULL));
  
  printf("before exit\n");
  printf("%d\n", pthread_cancel(p1));
  printf("after exit\n");
  printf("%d\n", pthread_cancel(p2));
  printf("both thread exited\n");
  
  printf("%d\n", pthread_join(p1, NULL));
  printf("%d\n", pthread_join(p2, NULL));
  printf("terminated\n");
  
  printf("%d\n", pthread_kill(p1, 0));
  printf("%d\n", pthread_kill(p2, 0));
  printf("ext\n");
  
  printf("%d\n", pthread_join(p1, NULL));
  printf("%d\n", pthread_join(p2, NULL));
  printf("jion\n");
  
  return 0;
  }
  
  void *run (void *p) {
  
  int *i = (int*)p;
  printf("created i = %d\n", *i);
  }
  </code></pre>
  
  <p>This is the code i am using. in this pthread_cancel on wards all function returning 3 which means thread is being already killed. </p>