Boost logo

Threads-Devel :

From: Sam Lievesley (sam.lievesley_at_[hidden])
Date: 2007-08-10 12:57:16


I am trying to avoid thread locking problems when waiting using a boost::condition

pseudo code:

Main thread

    -- Start a worker thread --
    boost::mutex::scoped_lock lock(m_Mutex);

Worker thread

    boost::mutex::scoped_lock lock(m_Mutex);
    while (IsAlive()) {

            // do some work


As we can't predict which thread gets the mutex lock first lets assume that its the main thread. If this happens then m_Condition.wait will wait indefinitely as notify was called before wait. The only reliable way (that I can see) to prevent this is to never use wait, use a timed_wait instead and a loop. Why isn't the notification signal queued in the boost::condition object? Then the order of wait / notification would not be important.



Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at