c++ - Serialize io_service::post() execution with io_service::run() called only in a single thread -


if have io_service::run() running only in single thread, io_service::post() calls executed in same order request them executed, or can executed in arbitrary order , still need use strand forcing serialized execution?

the question has been treated before, e.g.

it spells out

if of following conditions true:

  • s.post(a) happens-before s.post(b)
  • ...

then asio_handler_invoke(a1, &a1) happens-before asio_handler_invoke(b1, &b1).

note single io thread creates implicit strand (docs)


note in relation other answer: of course doesn't hold when handler invocations done implicitly on completion of asynchronous operation.

note in following case:

async_op_1(..., s.wrap(a)); async_op_2(..., s.wrap(b)); 

the completion of first async operation perform s.dispatch(a), , second perform s.dispatch(b), order in performed unspecified. is, cannot state whether 1 happens-before other. therefore none of above conditions met , no ordering guarantee made.


Comments