title: About pthread_kill() behavior
body: <p>I have a question about pthread_kill() behavior.</p>
  
  <p>Here's a small code I'm trying out:</p>
  
  <pre><code>void my_handler1(int sig)
  {
      printf("my_handle1: Got signal %d, tid: %lu\n",sig,pthread_self());
      //exit(0);
  }
  
  void *thread_func1(void *arg)
  {
      struct sigaction my_action;
      my_action.sa_handler = my_handler1;
      my_action.sa_flags = SA_RESTART;
      sigaction(SIGUSR1, &amp;my_action, NULL);
      printf("thread_func1 exit\n");
  }
  
  
  void *thread_func2(void *arg)
  {
      int s;
      s = pthread_kill(tid1_g,SIGUSR1);
      if(s)
              handle_error(s,"tfunc2: pthread_kill");
  
      printf("thread_func2 exit\n");
  }
  
  
  int main()
  {
      int s = 0;
      pthread_t tid1;
  
      s = pthread_create(&amp;tid1,NULL,thread_func1,NULL);
      if(s)
              handle_error(s,"pthread_create1");
  
      tid1_g = tid1;
      printf("tid1: %lu\n",tid1);
      s = pthread_join(tid1,NULL);
      if(s)
              handle_error(s, "pthread_join");
  
      printf("After join tid1\n");
  
      pthread_t tid3;
      s = pthread_create(&amp;tid3,NULL,thread_func2,NULL);
      if(s)
              handle_error(s,"pthread_create3");
  
      s = pthread_join(tid3,NULL);
      if(s)
              handle_error(s, "pthread_join3");
  
      printf("After join tid3\n");
      return 0;
  }
  </code></pre>
  
  <p>The output I'm getting is: </p>
  
  <pre><code>tid1: 140269627565824
  thread_func1 exit
  After join tid1
  my_handle1: Got signal 10, tid: 140269627565824
  thread_func2 exit
  After join tid3
  </code></pre>
  
  <p>So, even though I'm calling pthread_kill() on a thread that has already finished, the handler for that thread is still getting called. Isn't pthread_kill() supposed to return error(ESRCH) in case the thread doesn't exist?</p>