Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}