Boost C++ Libraries: Ticket #4167: RFC: asio::io_service::async_stop() to handle signals https://svn.boost.org/trac10/ticket/4167 <h2 class="section" id="Problemstatement">Problem statement</h2> <p> asio::io_service has no way of stopping from within a signal handler. Sending a signal to a daemon is a common way to controlling its behavior (under POSIX). Calling { io_service.stop(); } from a signal handler is not guaranteed to be safe. </p> <h2 class="section" id="Implementationsuggestion">Implementation suggestion</h2> <p> Declare and implement a public interface with the following semantics: </p> <p> void io_service::async_stop(void); </p> <blockquote> <p> /<strong> Sets an internal flag in io_service to stop at the nearest event loop. May be called from a signal handler. */ </strong></p> </blockquote> <h2 class="section" id="Knownworkarounds">Known workarounds</h2> <p> Let the io_service listen to a pipe. Write to the pipe from within the signal handler. </p> <h2 class="section" id="References">References</h2> <p> &lt;URL:http://article.gmane.org/gmane.comp.lib.boost.user/58164&gt; </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4167 Trac 1.4.3 chris_kohlhoff Sat, 01 May 2010 22:41:58 GMT status, type changed; resolution set https://svn.boost.org/trac10/ticket/4167#comment:1 https://svn.boost.org/trac10/ticket/4167#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> Thanks for the suggestion, but I do not consider this the right approach for handling signals. The "correct" way would be to handle signals just like other asynchronous events. I will probably add this support at some point. </p> <p> In the meantime, you could use a pipe (as you said), but you can also process the signals synchronously using sigwait(). All of the HTTP server examples take this approach. </p> Ticket