Boost logo

Boost Users :

Subject: [Boost-users] condition_variable::timed_wait doesn't wait
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-03-09 04:49:19

I'm trying to use condition_variable::timed_wait without success.
Using the following code, the timed_wait returns immediatly also if
Receive() is never called.
Where I wrong?

void Receive()
  boost::lock_guard<boost::mutex> lock(_mut);

  //... code ...//

  _data_ready = true;

  // Notify and unlock the mutex

bool Send()
  boost::unique_lock<boost::mutex> lock(_mut);

  boost::xtime xt;
  xtime_get(&xt, boost::TIME_UTC);
  xt.sec += 5;

  _data_ready = false;

  //... send data ...//

  //wait for an answer..
  bool ready = _cond.timed_wait(lock, xt, boost::lambda::var(_data_ready));

  return ready;

I've also tried to use:

ptime t = second_clock::universal_time();
ptime timeout = t + milliseconds(cmd_timeout);

bool ready = _cond.timed_wait(lock, timeout,

but with the same effect.


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