title: Are std::signal and std::raise thread-safe?
body: <p>The C and C++ standards support the concept of signal. However, the C11 standard says that the function signal() cannot be called in multi-threaded environments, or the behavior is undefined. But I think the signal mechanism is by nature for multi-threaded environments. </p>
  
  <p>A quote from the C11 standard 7.14.1.1.7</p>
  
  <blockquote>
    <p>"Use of this function in a multi-threaded program results in undefined behavior. The
    implementation shall behave as if no library function calls the signal function."</p>
  </blockquote>
  
  <p>Any explanations about this?</p>
  
  <p>The following code is self-evident.</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;csignal&gt;
  
  using namespace std;
  
  void SignalHandler(int)
  {
      // Which thread context here?
  }
  
  void f()
  {
      //
      // Running in another thread context.
      //
      raise(SIGINT); // Is this call safe?
  }
  
  int main()
  {
      //
      // Register the signal handler in main thread context.
      //
      signal(SIGINT, SignalHandler);
  
      thread(f).join();
  }
  </code></pre>