Boost logo

Boost Users :

Subject: [Boost-users] [thread/condition_variable] crashes in condition variable
From: Dietmar Hummel (hummel_at_[hidden])
Date: 2010-07-21 04:45:26

Hi all!

I have a problem with the condition variable class. I wrote a sync
object class (something which two threads have a reference to, the one
is waiting on in in wait() the other will signal it with signal().

This is some pseudo code which illustrates my problem:

function doSomething()
        // the sync object is to keep this thread
        // waiting until the other one is done
        CPGSUSyncObject cSyncObject;

        // give a pointer of the sync object to another thread

        // at one time in the future the other thread will call
        // its signal routine which calls condition_variable::notify_all

        // wait until the other one has done its tasks

My problem (as far as I can see it) is the following:

condition_variable::notify_all() calls wake_waiters() but does further
tasks after this call (I assume that wake_waiters() is doing the real
signalling by the os?). But if I have the task switch fast enough, it
may happen that my doSomething() method runs out of scope deleting
cSyncObject which is itself deleting the condition_variable. So the
vector iteration code in condition_variable::notify_all() crashes
because the object is already destroyed...

Any help or good hints are appreciated...


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at