
However, I'm still interested whether stop() should always cancel the queued handlers, i.e. if this is a bug (on windows). The io_service documentation says this regarding the use of a work object (http://alturl.com/98rvq):
"To effect a shutdown, the application will then need to call the io_service object's stop() member function. This will cause the io_service run() call to return as soon as possible, abandoning unfinished operations and without permitting ready handlers to be dispatched. Alternatively, if the application requires that all operations and handlers be allowed to finish normally, the work object may be explicitly destroyed."
I think (I've just inspected the Asio code) this behavior is designed in such a way for performance reasons - to not check "stopped" flag too often. Even the "stopped" flag is just an atomic value - it's Windows IOCP where OS uses specific technics for scheduling IOCP-tied threads and, may be, the author of Asio thinks (or even knows/has experience) that even atomic-value-check degrades performance or brakes specific scheduling of IOCP-tied threads. Regards, Marat Abrarov.