Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread/condition_variable] crashes in condition variable
From: Eric J. Holtman (eric_at_[hidden])
Date: 2010-07-21 07:34:17

On 7/21/2010 3:45 AM, Dietmar Hummel wrote:
> 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...

There's also a choice (3) which I forgot:

In your second thread, if you call "signal" while
the mutex is locked, this problem will go away.

There are tons of articles around on whether or not
you should do this (having to do with context switching
and performance), but it will solve your problem.

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