andre
andre

Reputation: 7249

Does boost::io_service::post queue request?

I'm using boost::io_service as follows.

boost::io_service service;
service.post(boost::bind(...));
service.post(boost::bind(...));
service.post(boost::bind(...));

I want to understand if post is queuing my request, guaranteeing order of execution or can request be dropped. I've searched the boost documentation for the answer without luck.

Upvotes: 0

Views: 672

Answers (1)

Chad
Chad

Reputation: 19032

No, the order of execution is not guaranteed by default.

When a callback is posted to an io_service, that callback will be called at "the appropriate time" as long as the underlying io_service is being actively polled by some thread (using one of the following functions: run(), run_one(), poll(), poll_one()).

Some commands that can be posted may not ever return (such as an asynchronous read on a socket, where no data is ever sent). These types of asynchronous actions usually will provide an error code to the callback that can be checked. This error code in certain cases will give details about the success (or failure) of an operation. In the cited example above, pending asynchronous reads will have their callbacks executed with the error code "operation aborted" if the underlying socket is closed.

Upvotes: 1

Related Questions