本文整理汇总了C++中boost::condition_variable_any::wait_for方法的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable_any::wait_for方法的具体用法?C++ condition_variable_any::wait_for怎么用?C++ condition_variable_any::wait_for使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::condition_variable_any
的用法示例。
在下文中一共展示了condition_variable_any::wait_for方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
void f()
{
typedef boost::chrono::system_clock Clock;
typedef boost::chrono::milliseconds milliseconds;
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
BOOST_TEST(t1 - t0 < milliseconds(250));
BOOST_TEST(test2 != 0);
}
else
{
BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(250+5));
BOOST_TEST(test2 == 0);
}
++runs;
}
示例2: f
void f()
{
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + milliseconds(250);
while (test2 == 0 && cv.wait_for(lk, t - Clock::now()) == boost::cv_status::no_timeout) {}
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 != 0);
}
else
{
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 == 0);
}
++runs;
}