I found that asio's doc about synchronization by strand
is obscure. It just says that in a thread pool design asio app, the handler can be run in any thread which had call io_service::run()
. Using a strand
to warp these handler can make their execution concurrent correctly. In its example3, all handle_read
are wrap by strand
, and I think the variables in Connection
class such as buffer
has been synchronized by strand
, different thread calls handle_read
will gets up-to-date data, that is OK. But what about there is a data member defined in Connection
class which also accessed by a handler was not wrap by strand
? I think this is a problem, isn't it?
In its doc example3, why handle_accept
was not wrap by a strand
? The new_connection_
is accessed by multi threads: new_connection_.reset
called by thread A and server::handle_accept
called by thread B. I think it needs data synchronization here or else thread B might use a out-of-date new_connection_
that its reset have not been called yet.