Hi,

In the Boost.Asio docs (and in the standalone Asio) the io_service docs has a section "Stopping the io_service from running out of work" where it explains "if the application requires that all operations and handlers be allowed to finish normally, the work object may be explicitly destroyed" and then shows some code using an std::auto_ptr<boost::asio::io_service::work> which will keep the work object on the heap.

However, in the accepted answer to [1] the same behavior is accomplished with a, IMHO, more elegant solution: with a boost::optional<boost::asio::io_service::work>, which, if I'm correct, will keep the work object on the stack. To destroy the work object the optional is assigned to boost::none.

I'd suggest improving the docs with the boost::optional case, which
 - does not use "ugly" (and deprecated) auto_ptr
 - keeps the boost::asio::io_service::work object on the stack

Regards

[1] http://stackoverflow.com/questions/15568100/confused-when-boostasioio-service-run-method-blocks-unblocks