本文整理汇总了C++中boost::timed_mutex::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ timed_mutex::lock方法的具体用法?C++ timed_mutex::lock怎么用?C++ timed_mutex::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::timed_mutex
的用法示例。
在下文中一共展示了timed_mutex::lock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();
boost::thread t(f2);
boost::this_thread::sleep_for(ms(750));
m.unlock();
t.join();
}
return boost::report_errors();
}
示例2: f
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
m.lock();
t1 = Clock::now();
m.unlock();
#else
//time_point t0 = Clock::now();
m.lock();
//time_point t1 = Clock::now();
m.unlock();
//ns d = t1 - t0 - ms(250);
//BOOST_TEST(d < max_diff);
#endif
}
示例3: f
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
time_point t0 = Clock::now();
m.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(2500000)+ms(1000)); // within 2.5ms
#else
//time_point t0 = Clock::now();
m.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(2500000)+ms(1000)); // within 2.5ms
#endif
}
示例4: main
int main()
{
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#else
#endif
m.unlock();
t.join();
return boost::report_errors();
}