Boost logo

Threads-Devel :

From: Anteru (newsgroups_at_[hidden])
Date: 2008-04-19 05:46:37


Hi,

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
happens:

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"
http://www.cs.wustl.edu/~schmidt/win32-cv-1.html - 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?

Cheers,
   Anteru


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk