void f() { L1 lk(m0); assert(test2 == 0); test1 = 1; cv.notify_one(); Clock::time_point t0 = Clock::now(); Clock::time_point t = t0 + Clock::duration(250); while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout) ; Clock::time_point t1 = Clock::now(); if (runs == 0) { assert(t1 - t0 < Clock::duration(250)); assert(test2 != 0); } else { assert(t1 - t0 - Clock::duration(250) < Clock::duration(5)); assert(test2 == 0); } ++runs; }
void f() { L1 lk(m0); assert(test2 == 0); test1 = 1; cv.notify_one(); Clock::time_point t0 = Clock::now(); Clock::time_point t = t0 + Clock::duration(250); bool r = cv.wait_until(lk, t, Pred(test2)); Clock::time_point t1 = Clock::now(); if (runs == 0) { assert(t1 - t0 < Clock::duration(250)); assert(test2 != 0); assert(r); } else { assert(t1 - t0 - Clock::duration(250) < Clock::duration(2)); assert(test2 == 0); assert(!r); } ++runs; }