Boost logo

Threads-Devel :

From: Anteru (newsgroups_at_[hidden])
Date: 2008-04-19 06:37:01

I hope this does not appear twice, seems Gmane ate my first message to
this list.


I've posted this to the users list as well, but it might have got lost
as I replied on the original thread.

Well, I still have problems with the conditions, even with the latest
SVN. The problem seems to be that inside a block like:

Lock lock (mutex);

while (something.empty ())
     cond.wait (mutex);

I'm still getting into a state where something.empty () == false and yet
I'm waiting on the condition. The only other access happens via:

Lock lock (mutex);

something.push (...);
cond.notify_one ();

So I don't get it how something can go wrong, unless the transition from
mutex.unlock () to cond.wait () is not fully atomic and the following

Thread 1: Thread 2:
while (something.empty ())
     cond.wait (mutex);
// starts, releaes lock but is not waiting yet
                     Lock lock ();
                     something.push (..);
                     cond.notify_one ();
// Nobody waiting
                     lock.release ();
     cond.wait (mutex); // starts waiting

I had a similar problem with my own condition implementation on Windows,
with exactly the same syndromes (I've been following the "Strategies for
Implementing POSIX Condition Variables on Win32" - only got it working
properly with SignalObjectAndWait).

Currently, it always leaves exactly *one* thread waiting, while
previously, it left several threads waiting, so it has improved but
there is still a problem.

Any ideas? Anything I can do to track this down further?


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