typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
+#ifdef BOOST_THREAD_PLATFORM_WIN32
+const ms max_diff(250);
+#else
+const ms max_diff(75);
+#endif
+
void f1()
{
time_point t0 = Clock::now();
- // This test is spurious as it depends on the time the thread system switches the threads
- boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(300)+ms(1000));
+ boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(750));
BOOST_TEST(lk.owns_lock() == true);
time_point t1 = Clock::now();
- // This test is spurious as it depends on the time the thread system switches the threads
ns d = t1 - t0 - ms(250);
- BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms
+ BOOST_TEST(d < max_diff);
}
void f2()
BOOST_TEST(lk.owns_lock() == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
- // This test is spurious as it depends on the time the thread system switches the threads
- BOOST_TEST(d < ns(5000000)+ms(1000)); // within 5ms
+ BOOST_TEST(d < max_diff);
}
int main()
{
m.lock();
boost::thread t(f2);
- boost::this_thread::sleep_for(ms(350));
+ boost::this_thread::sleep_for(ms(750));
m.unlock();
t.join();
}