Boost logo

Boost Users :

From: David A. Greene (greened_at_[hidden])
Date: 2006-02-09 20:20:04


David Greene wrote:
> void push(int val) {
> LOG_NOLCK("push(): about to lock");
> {
> lock_type lock(mutex);
> LOG_NOLCK("push(): locked");
> queue.push(val);
>
> lock_type full_lock(full_mutex);
> LOG_NOLCK("push(): about to unlock");
> }
> full_condition.notify_all();
> };

Whoops! This is a race condition. Because the full_lock is
released, there's no guaratee the consumer is waiting on the
condition and the signal may be lost. When I moved the lock
after the inner brace, everything started working.

                              -Dave


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net