[asio] are defer/dispatch/post identical?
Hi, 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. Thanks, F
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/Executor... https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/reference/io_conte... 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.
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.
Thank you very much, that's clear now. F
participants (2)
-
Frédéric
-
Gavin Lambert