title: posix threads block signal and unblock
body: <p>Is there a way to block certain signals and unblock other signals in the same set?
  I just dont seem to get my head around it!</p>
  
  <p>An example</p>
  
  <pre><code>sigset_t set;
  sigemptyset(&amp;set);
  
  sigaddset(&amp;set, SIGUSR1);
  // Block signal SIGUSR1 in this thread
  pthread_sigmask(SIG_BLOCK, &amp;set, NULL);
  sigaddset(&amp;set, SIGALRM);
  // Listen to signal SIGUSR2
  pthread_sigmask(SIG_UNBLOCK, &amp;set, NULL);
  
  
  pthread_t printer_thread1, printer_thread2;
  pthread_create(&amp;printer_thread1, NULL, print, (void *)&amp;f1);
  pthread_create(&amp;printer_thread2, NULL, print, (void *)&amp;f2);
  
  bool tl = true;
  while(1)
  {
      if(tl)
      {
          // thread1 does something
          kill(pid, SIGUSR1);
          // main thread waits for SIGALRM
          sigwait(&amp;set, &amp;sig);
          tl = !tl;
      }
      else
      {
          // thread2 does something
          kill(pid, SIGUSR2);
          // main thread waits for SIGALRM
          sigwait(&amp;set, &amp;sig);
          tl = !tl;
      }
  }
  </code></pre>
  
  <p>I am not allowed to use Mutexs, semaphores etc only signals.</p>
  
  <p>Can someone help? :)</p>