The requirement for boost::asio::ssl:::stream
is for thread safety; it does not place a requirement as to which thread may initiate operations:
Distinct objects: Safe.
Shared objects: Unsafe. The application must also ensure that all asynchronous operations are performed within the same implicit or explicit strand.
If the application only has one thread processing the io_service
, and async_read()
and async_write()
are initiated from within that thread, then it is safe, as the operation and completion handler(s) are running within an implicit strand.
On the other hand, if multiple threads are processing the io_service
, then an explicit strand
is necessary. The async_read()
and async_write()
operations need to be initiated from within a strand
, and the completion handlers need to be wrapped by the same strand
.
For more details on Boost.Asio's thread safety requirements, strands
, and composed operations, consider reading this answer.