Subject: [Boost-bugs] [Boost C++ Libraries] #9708: regression: boost::condition_variable::timed_wait unexpectedly wakes up while should wait infinite
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-02-25 05:17:29
#9708: regression: boost::condition_variable::timed_wait unexpectedly wakes up
while should wait infinite
------------------------------+------------------------
Reporter: nikolay@⦠| Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.52.0 | Severity: Regression
Keywords: |
------------------------------+------------------------
After upgdate from boost 1.44 to boost 1.52 following issue appears:
boost::condition_variable::timed_wait(...,
boost::posix_time::time_duration(boost::posix_time::pos_infin)) always
immediately return false.
In boost 1.44 it waits infinite for a condition notified.
Simple test:
{{{#!cpp
int _tmain(int argc, _TCHAR* argv[])
{
// test std
std::condition_variable scv;
std::mutex sm;
bool flag = false;
std::thread t([&]()
{
std::unique_lock<std::mutex> l(sm);
if (std::cv_status::timeout == scv.wait_for(l,
std::chrono::duration<int, std::ratio<1,1>>::max()))
{
// wait_for return timeout. it means that time
period has elapsed.
std::terminate();
}
if (!flag)
std::terminate(); // we should sleep yet
});
std::this_thread::sleep_for(std::chrono::seconds(2));
{
std::unique_lock<std::mutex> l(sm);
flag = true;
}
scv.notify_one();
t.join();
// test boost
boost::condition_variable bcv;
boost::mutex bm;
flag = false;
std::thread bt([&]()
{
boost::unique_lock<boost::mutex> l(bm);
if (!bcv.timed_wait(l,
boost::posix_time::time_duration(boost::posix_time::pos_infin)))
{
// timed_wait return false. it means that time
period has elapsed.
std::terminate(); // positive infinite should
never be elapsed
}
if (!flag)
std::terminate(); // we should sleep yet
});
std::this_thread::sleep_for(std::chrono::seconds(2));
{
boost::unique_lock<boost::mutex> l(bm);
flag = true;
}
bcv.notify_one();
bt.join();
return 0;
}
}}}
compiled: MSVS2012 UP4, Win7 Pro.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9708> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC