I am using Boost::ASIO version 1.52.0 for a Windows client. I would like to be able to dedicate a thread to handling all receiving messages from the server, and then another dedicated thread to handle all outgoing messages to the server. I am using the same io_service
object for both threads right now. What I'm worried about is that when the io_service::run()
method is called, the thread that is handling the outgoing messages, might get scheduled to handle some incoming message calls and vice-a-versa. So, my question - is this possible? If it is, then would using a second io_service
object solve the problem - one for each thread? Is there a better way to design this? I am trying to avoid using multiple threads for both the read and write handlers.
The other thing I would like confirmation on is - I have read that a lock should be used to single thread the code if 2 or more async_reads
can be done at the same time. Likewise for async_writes
. Should a lock also be used if an async
_read can execute at the same time as an async_write
, or should that be thread safe?
One last question - can the async methods - async_connect
, async_read
, and async_write
all be called from a different thread before a worker thread has called the io_service
run method?