The io_service::stop()
is being invoked within the cancelled SignalHandler
, causing all invocations of io_service::run()
to return as soon as possible.
void DispatcherClass::AddCtrlCHandling()
{
boost::asio::signal_set sig_set(...);
sig_set.async_wait(boost::bind(
&boost::asio::io_service::stop, boost::ref(_ioService)));
}
In DispatcherClass::AddCtrlCHandling()
, the sig_set
is an automatic variable with a type of boost::asio::signal_set
with its lifetime ending once the function returns. In the signal_set
destructor, all outstanding asynchronous wait operations on the signal_set
will be completed with an error code of boost::asio::error::operation_aborted
. Hence, a SignalHandler
that will invoke io_service::stop()
is queued into the io_service
and invoked by one of the worker threads. To resolve this, consider extending the signal_set
's lifetime by making sig_set
a member variable of DispatcherClass
.