示例#1
0
void f()
{
  time_point t0 = Clock::now();
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  while (!m.try_lock())
    ;
  time_point t1 = Clock::now();
  m.unlock();
  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(50000000)+ms(1000)); // within 50ms
}
示例#2
0
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
  t0 = Clock::now();
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  while (!m.try_lock())
    ;
  t1 = Clock::now();
  m.unlock();
#else
  //time_point t0 = Clock::now();
  //BOOST_TEST(!m.try_lock());
  //BOOST_TEST(!m.try_lock());
  //BOOST_TEST(!m.try_lock());
  while (!m.try_lock())
    ;
  //time_point t1 = Clock::now();
  m.unlock();
  //ns d = t1 - t0 - ms(250);
  //BOOST_TEST(d < max_diff);
#endif
}