|
Boost Users : |
From: Igor R (boost.lists_at_[hidden])
Date: 2008-05-29 14:01:58
> 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_client.cpp
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net