title: boost::asio signal_set handler only executes after first signal is caught and ignores consecutive signals of the same type
body: <p>I have a program and would like to stop it by sending <code>SIGINT</code> for writing some data to a file instead of exiting immediately. However, if the user of the program sends <code>SIGINT</code> again, then the program should quit immediately and forget about writing data to a file.</p>
  
  <p>For portability reason I would like to use <code>boost::asio</code> for this purpose.</p>
  
  <p>My initial (simplified) approach (see below) did not work. Is this not possible or am I missing something?</p>
  
  <p>The handler seems to be called only once (printing out the message) and the program always stops when the loop has reached the max iteration number.</p>
  
  <pre><code>void handler(
  const boost::system::error_code&amp; error,
  int signal_number) {
      if (!error) {
          static bool first = true;
          if(first) {
              std::cout &lt;&lt; " A signal(SIGINT) occurred." &lt;&lt; std::endl;
              // do something like writing data to a file
              first = false;
          }
          else {
              std::cout &lt;&lt; " A signal(SIGINT) occurred, exiting...." &lt;&lt; std::endl;
              exit(0);
          }
      }
  }
  
  int main() {
      // Construct a signal set registered for process termination.
      boost::asio::io_service io;
      boost::asio::signal_set signals(io, SIGINT);
  
      // Start an asynchronous wait for one of the signals to occur.
      signals.async_wait(handler);
      io.run();
      size_t i;
  
      for(i=0;i&lt;std::numeric_limits&lt;size_t&gt;::max();++i){
          // time stepping loop, do some computations
      }
  
      std::cout &lt;&lt; i &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>