
I want to be able to have multiple threads sending a "start" or a "stop" to all connected daemons using boost::asio::async_write(). But this has to be in phases, so all threads handling a "start" should finish first before a "stop" can be initiated.
I'm not sure I understand your question correctly: do you wish to send these messages to the *same* socket from *multiple* threads? Or one daemon is served by one socket and one thread? Anyway, you have to be aware of an important point: after you issued async_XXX call, you should wait until it's complete before you can issue another async. call of that type. Eg., if you've called async_write(), then you may issue another async_write() not before the completion handler of the 1st one is called (see asio examples for details). Besides, if you'd like to send messages from different threads, you can just post your message, using io_service::post(), so that you avoid messing with explicit synchronization. See chat_client example: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/example/chat/chat_c...