RE: Re: [boost] Implementing WaitForMultipleObjects using boost

Hi
I was checking out if I could use Boost to port code written for Windows to Unix.
The code has calls to WaitForMultipleObject which I would need to replace.
You can always do the same thing by means of conditions and signals. The paradigm is slightly different, though. //... boost::condition cond; object1.signal.connect(boost::bind(&boost::condition::notify_all, &cond)); object2.signal.connect(boost::bind(&boost::condition::notify_all, &cond)); cond.wait(mutex_lock); //... In this case, the objects have explicit signals (consider the parallel to windows kernel objects, which have an implicit "signal", i.e. their wait state). Regards David Turner

David Turner <dkturner <at> telkomsa.net> writes:
Hi
I was checking out if I could use Boost to port code written for Windows to Unix.
The code has calls to WaitForMultipleObject which I would need to replace.
You can always do the same thing by means of conditions and signals. The paradigm is slightly different, though.
//... boost::condition cond; object1.signal.connect(boost::bind(&boost::condition::notify_all, &cond)); object2.signal.connect(boost::bind(&boost::condition::notify_all, &cond)); cond.wait(mutex_lock); //...
From the current signals FAQ: <quote>
2. Is Boost.Signals thread-safe? No. Using Boost.Signals in a multithreaded concept is very dangerous, and it is very likely that the results will be less than satisfying. Boost.Signals will support thread safety in the future. </quote> I see that what you describe *can* be MT-safe nevertheless but only if you pay a lot of attention to the details, i.e. object1.signal.connect() must not be called while another thread could simultaneously call object1.signal(). This can often not be guaranteed and users would therefore have to protect the signal manually. Regards, Andreas
participants (2)
-
Andreas Huber
-
David Turner