ACE_Guard<ACE_Thread_Mutex> guard(mutex_);
while (value != expected_value)
condition_.wait();
The cool thing is that boost's condition variable wait() method takes a predicate functor to handle spurious wakeup.
struct CompareVariable {
bool operator()() const {
return value_ != expected_value_;
}
int value_, expected_value_;
} pred;
boost::mutex::scoped_lock guard(mutex_);
condition.wait(guard, pred);
The
condition.wait(guard, pred);above is equivalent to
while (!pred())wait(lock);
1 comment:
Very niice blog you have here
Post a Comment