[asio] are defer/dispatch/post identical?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[asio] are defer/dispatch/post identical?

Boost - Users mailing list
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
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [asio] are defer/dispatch/post identical?

Boost - Users mailing list
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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [asio] are defer/dispatch/post identical?

Boost - Users mailing list
> 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
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users