title: sigwait() and signal handler
body: <p>If I setup and signal handler for SIGABRT and meanwhile I have a thread that waits on sigwait() for SIGABRT to come (I have a blocked SIGABRT in other threads by pthread_sigmask).</p>
  
  <p>So which one will be processed first ? Signal handler or sigwait()  ? </p>
  
  <p>[I am facing some issues that sigwait() is get blocked for ever. I am debugging it currently]</p>
  
  <pre><code>main()
  {
      sigset_t                    signal_set;
  
      sigemptyset(&amp;signal_set);
      sigaddset(&amp;signal_set, SIGABRT); 
      sigprocmask(SIG_BLOCK, &amp;signal_set, NULL); 
  
      // Dont deliver SIGABORT while running this thread and it's kids.
      pthread_sigmask(SIG_BLOCK, &amp;signal_set, NULL);
  
      pthread_create(&amp;tAbortWaitThread, NULL, WaitForAbortThread, NULL);
      ..
      Create all other threads
      ...
  }   
  
  static void*    WaitForAbortThread(void* v)
  {
      sigset_t signal_set;
      int stat;
      int sig;
  
      sigfillset( &amp;signal_set);
      pthread_sigmask( SIG_BLOCK, &amp;signal_set, NULL ); // Dont want any signals
  
  
      sigemptyset(&amp;signal_set);
      sigaddset(&amp;signal_set, SIGABRT);     // Add only SIGABRT
  
      // This thread while executing , will handle the SIGABORT signal via signal handler.
      pthread_sigmask(SIG_UNBLOCK, &amp;signal_set, NULL); 
      stat= sigwait( &amp;signal_set, &amp;sig  ); // lets wait for signal handled in CatchAbort().
      while (stat == -1)
      {
          stat= sigwait( &amp;signal_set, &amp;sig  );
      }
  
      TellAllThreadsWeAreGoingDown();
  
      sleep(10);
  
      return null;
  }
  
  // Abort signal handler executed via sigaction().
  static void CatchAbort(int i, siginfo_t* info, void* v)
  {
      sleep(20); // Dont return , hold on till the other threads are down.
  }
  </code></pre>
  
  <p>Here at sigwait(), i will come to know that SIGABRT is received. I will tell other threads about it. Then will hold abort signal handler so that process is not terminated. </p>
  
  <p>I wanted to know the interaction of sigwait() and the signal handler.</p>