c++ - boost.asio compound operations in single and multi threaded processes -
there several things boost.asio compound operations not clear official documentation , various threads have read on topic.
the scenario
two boost::asio::async_write requests , b scheduled on single tcp socket.
questions
in single-threaded process, can happen executed concurrently b? namely, intermediate callsasync_write_some of mixed of b (which renders corrupted stream)? if reply (1) yes, io_service::strand solve issue in single-threaded process? assure intermediate calls of finish before b started? does io_service.strand solve issue of (1) in multi-threaded process, when more 1 thread execute io_service::run()? assure intermediate calls of finish before b started?
the documentations states explicitly: "the programme must ensure stream performs no other write operations (such async_write, stream's async_write_some function, or other composed operations perform writes) until operation completes."
so, multiple async_write's must never called concurrently. in single-threaded case, 1 can chain them, calling subsequent async_write in completion hanndler of previous one.
if io_service::run run in multiple threads, wrap async_write's completion handler strand, , asio will synchronize intermediate internal handlers.
c++ multithreading boost boost-asio
No comments:
Post a Comment