title: How to block all SIGNALS in thread WITHOUT using SIGWAIT?
body: <p>I have a main application that spawns a seperate thread to process messages off a queue. I have an issue on AIX when I hit CTRL-C as it seems to make some "connection handles" in the thread become invalid. I do have a shutdown hook in the main program catching the SIGINT but on AIX it seems to somehow send a signal to the thread as well...although that is not really possible from what I hear...</p>
  
  <p>Essentially I would like to know if I want the MAIN application to handle ALL signals I am interested in and have the thread/s NEVER handle any signals...is that "good practice"?</p>
  
  <p>If so how can I NOT use "sigwait" in the thread...in fact I do not want any "signal code" in the thread/s...they must simply not receive any signals at all.</p>
  
  <p>I have emptied out all the signals:</p>
  
  <pre><code>sigemptyset(&amp;set);
  </code></pre>
  
  <p>And have set the SIG_BLOCK</p>
  
  <pre><code>s = pthread_sigmask(SIG_BLOCK, &amp;set, NULL);
  </code></pre>
  
  <p>So here is a dummy test programe:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;errno.h&gt;
  
  #define handle_error_en(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
  
  static void * threadMainLoop(){
      //Here I do not want the thread to use "sigwait"....
      while(running == TRUE){
        //do some thread work and never have any signals come in
      }
  }
  
  void shutdownHook(int sig){
      printf("\nCtrl-C pressed....shutdown hook in main...\n");
  }
  
  void signalErrorHandler(int signum){
      printf("\nSignal error handler in main...\n");
  }
  
  int main(int argc, char *argv[]){
      pthread_t thread;
      sigset_t set;
      int s;
  
      //Catch the following signals in the MAIN thread
      (void) signal(SIGINT, shutdownHook);
      (void) signal(SIGSEGV, signalErrorHandler);
      (void) signal(SIGBUS, signalErrorHandler);
      (void) signal(SIGILL, signalErrorHandler);
      (void) signal(SIGTERM, signalErrorHandler);
      (void) signal(SIGABRT, signalErrorHandler);
  
      sigemptyset(&amp;set); //BLOCK all signals
  
      s = pthread_sigmask(SIG_BLOCK, &amp;set, NULL);
      if (s != 0)
          handle_error_en(s, "pthread_sigmask");
  
      s = pthread_create(&amp;thread, NULL, &amp;threadMainLoop, (void *) NULL);
      if (s != 0)
          handle_error_en(s, "pthread_create");  
  
      pause();
  }
  </code></pre>
  
  <p>If I just create a thread and have, for example, the SIGINT signal handler in the MAIN thread but do NOT has the SIG_BLOCK set for the thread and the user hits CTRL-C....does the thread get affected at all even though the signal handler in the main thread runs? That seems to be what I am seeing on AIX ;-(</p>
  
  <p>Thanks for the help, much appreciated</p>
  
  <p>Lynton</p>