Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Does stop() cancel handlers post()ed to io_service?
From: Marat Abrarov (abrarov_at_[hidden])
Date: 2013-06-26 11:07:36


> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net