title: Using a signal listener thread - how do I stop it?
body: <p>A snippet from my main method:</p>
  <pre><code>  std::atomic_bool runflag;
    // ...
    std::thread signaller([&amp;]() mutable {
      while (runflag) {
        int sig;
        int rcode = sigwait(&amp;set, &amp;sig);
        if (rcode == 0) {
          switch (sig) {
            case SIGINT: {
              // handle ^C
            }
          }
        }
      }
    });
    
    while (runflag) {
      next = cin.get();
      // handle character input
    }
    signaller.join();
  </code></pre>
  <p>I'm using the <code>sigwait()</code>-based approach for detecting <code>SIGINT</code> sent from the command line.</p>
  <p>The <code>signaller</code> thread uses <code>sigwait()</code> to listen for signals. The program terminates when <code>runflag</code> is set false. However, the <code>signaller</code> thread will still be blocked at <code>sigwait</code> when this happens. I don't think I can use condition variables, as sigwait has no way to hook into one. Is there an alternative solution that is preferably not Linux-only?</p>
  <p>EDIT 1: Alternatively, is there an interruptible version of sigwait?</p>