title: signal handler function in multithreaded environment
body: <p>In my multithreaded GUI application I have the following signal handling code. I want to improve this code so that it will be correct and threading safe but there are some things I don't fully understand in signal handling:</p>
  
  <ul>
  <li>is signal handled at the process or thread level (can I have thread-specific signal handlers) ?</li>
  <li>in which thread context is signal_handler function executed ?</li>
  <li>is it possible to send many SIGTERM signals in a short time ?</li>
  <li>does it make sense to use a mutex to prevent parallel execution of signal_handler ?</li>
  </ul>
  
  <hr>
  
  <pre><code>void signal_handler(int sig)
  {
          switch (sig)
          {
          case SIGTERM:
              ::wxLogMessage(wxT("SIGTERM signal received ..."));
              break;
          case SIGINT:
              ::wxLogMessage(wxT("SIGINT signal received ..."));
              break;
          case SIGUSR1:
              ::wxLogMessage(wxT("SIGUSR1 signal received ..."));
              break;
          default:
              ::wxLogMessage(wxT("Unknown signal received ..."));
          }
  
          // send wxCloseEvent to main application window
          ::wxGetApp().GetTopWindow()-&gt;Close(true);
  }
  </code></pre>
  
  <p>I register signal handlers in my init function:</p>
  
  <pre><code>// register signal handlers
  signal(SIGTERM, signal_handler);
  signal(SIGINT,  signal_handler);
  signal(SIGUSR1, signal_handler);
  </code></pre>