Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] are defer/dispatch/post identical?
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-09-17 23:14:51


On 18/09/2018 00:59, Frédéric wrote:
> Is there a difference between defer, dispatch and post free functions?
> They look very similar, there files look the same apart from the fact
> that they call defer, dispatch and post of the executor. The doc in
> executor seems to be the same.

https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/reference/Executor1.html

https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/reference/io_context__executor_type.html

They're very similar, but the difference is in what can happen to the
current thread.

dispatch is allowed (but not required) to execute the complete provided
function (if in the correct context already) before returning to the caller.

post is required to return to the caller immediately without directly
starting execution of the method (although it might still start
executing on another thread before it returns, depending on the executor).

defer is mostly like post but it will generally prefer to wait until the
current method finishes and then execute on the same thread, rather than
starting immediately on a different thread.

If there's only one thread in the pool, then defer and post behave
identically.


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