$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] condition_variable::timed_wait doesn't wait
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-03-09 04:49:19
Hi!
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
  _cond.notify_one();
}
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,
boost::lambda::var(_data_ready));
but with the same effect.
Thanks,
Daniele.