Io_service :: run () the processing order of the async_ * functions

Suppose that when calling io_service :: run (), several async_read operations are scheduled (there may be other operations between them). What happens when an asynchronous operation, such as async_write, is scheduled in the ReadHandler function?

void handler(const boost::system::error_code& error, std::size_t bytes) {
    async_write(sock, boost::asio::buffer(wbuf), whandler);
}

That is, when will async_write be called? I expect the execution order to be as follows:

1) async_read //1
2) async_write
3) async_read //2
4) async_write

Is this order of execution guaranteed?

+4
source share
3 answers

, . , , , ? , . , , ? , , .

+3

boost::asio.

.

boost::asio::async_read docs:

This operation is performed in terms of zero or more calls to stream async_read_some and is known as a composed operation. The program must ensure that the thread does not perform any other read operations (such as async_read, the stream of the async_read_some functions, or any other linked operations that perform reads) while this operation completes.

+1
source

All Articles