title: master / worker threads and signal handling
body: <p>I am writing a program, with a master thread and some worker threads, and I would like to get the signal handling right. My problem is the following :</p>
  
  <p>Master thread starts and do all allocation </p>
  
  <p>Master thread sets a SIGINT signal handler</p>
  
  <p>Master threads start worker threads. worker threads don't need special cleanup, however they can be sleeping on system call or semaphore.</p>
  
  <p>When SIGINT is received, my understanding is that only one thread receives it. So if thread are sleeping on system call or semaphore, they wont be waked up, and I won't be able to 
  pthread_join my worker threads and do all the necessary cleanup in my master thread.</p>
  
  <p>Can the following signal handler resolve my problem ?</p>
  
  <pre><code>void term(int sig)
  {
      g_do_cleanup = 1;
      pthread_kill(worker_1_id, some_other_signal);
      ...
      pthread_kill(worker_2_id, some_other_signal);
  }
  </code></pre>
  
  <p>What I expect is that upon receiving SIGINT, all thread will be signaled with another signal, get out of their blocking call, see the <code>g_do_cleanup</code> flag and gracefully exit.</p>
  
  <p>Any comment or link on how to do this properly is welcome.</p>
  
  <p>Edit :
  I am NOT looking for a way to wakeup multiple thread waiting on a particular condition, so I don't think the pthread_cond_signal approach is what I am looking for. What I want is :</p>
  
  <ul>
  <li>Find a way that all thread that are
  blocked on a blocking call returns
  from these calls.</li>
  <li>Or kill all threads except for the main one.</li>
  </ul>