[asio] is the io_context queue FIFO?
Is there a guarantee that the events posted using boost::asio::post() are called in the order of submission or can they be called in any order? Note that I have multiple threads running io_context.run(). Thanks, F
On 18/09/2018 01:07, Frédéric wrote:
Is there a guarantee that the events posted using boost::asio::post() are called in the order of submission or can they be called in any order? Note that I have multiple threads running io_context.run().
On Windows it's implemented using an I/O Completion Port, which is internally a FIFO queue. I'm not sure about the Linux implementation; there are a couple of different options there IIRC. In any case, once you have multiple consuming threads using the same queue it becomes a little harder to define what FIFO truly means, since one thread might be able to execute tasks 2 and 3 faster than another thread executes task 1. There are also other considerations, such as whether dispatch, defer, or post is used to queue up subsequent work. Typically if the order matters to you, you should enforce this by not starting operation 2 until operation 1 completes, and so forth.
On 18/09/2018 19:12, Frédéric wrote:
I'm not sure about the Linux implementation; there are a couple of different options there IIRC.
could you give me a hint on where I can find those options?
It defaults to using the best (most reliable and performant) option for your platform, so it's usually best not to mess with it. But if you really want, you can #define things to tell it to use a different backend. See: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/using.html
On Mon, 17 Sep 2018 at 14:08, Frédéric via Boost-users < boost-users@lists.boost.org> wrote:
Is there a guarantee that the events posted using boost::asio::post() are called in the order of submission or can they be called in any order? Note that I have multiple threads running io_context.run().
The asio documentation provides no guarantee of execution order at all, other than the execution of a dispatched function happens before the dispatch call returns.
From memory, previous versions of ASIO used to provide some guarantees around this, but since the current documentation does not mention it, one must assume that it's unknowable and code accordingly.
Thanks,
F _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
The asio documentation provides no guarantee of execution order at all, other than the execution of a dispatched function happens before the dispatch call returns.> From memory, previous versions of ASIO used to provide some guarantees around this, but since the current documentation does not mention it, one must assume that it's unknowable and code accordingly.
thanks, F
participants (3)
-
Frédéric
-
Gavin Lambert
-
Richard Hodges