Understanding boost::asio::post with single callable - who executes?

Viewed 505

I would like to know how I should understand boost::asio::post

In particular this overload that can just take a single callable, who/what/where executes it now (since I don't explicit pass it an io_service/io_context for example) ?

Does it just randomly (more or less) choose a running io_service (if there is one) ? I feel like there is something Im completely missing.

2 Answers

Eventually, boost::asio::post will use get_associated_executor to look up a specialization of associated_executor. The default implementation will provide a static instance of system_executor, where the object will be invoked.

Dave S's answer is correct, but if a writer of the code is confused with the default signature, imagine what will happen to a reader! Maybe better to just use this or this overload with explicit execution context argument instead.

Related