1 // Copyright (C) 2011 Vicente J. Botet Escriba
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // <boost/thread/strict_lock.hpp>
8 // template <class Lockable>
9 // strict_lock<Lockable> make_strict_lock(Lockable &);
11 #define BOOST_THREAD_VERSION 4
13 #include <boost/thread/strict_lock.hpp>
14 #include <boost/thread/mutex.hpp>
15 #include <boost/thread/thread.hpp>
17 #include <boost/detail/lightweight_test.hpp>
19 #ifdef BOOST_THREAD_USES_CHRONO
20 typedef boost::chrono::high_resolution_clock Clock;
21 typedef Clock::time_point time_point;
22 typedef Clock::duration duration;
23 typedef boost::chrono::milliseconds ms;
24 typedef boost::chrono::nanoseconds ns;
29 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO
33 time_point t0 = Clock::now();
36 const auto&& lg = boost::make_strict_lock(m); (void)lg;
39 ns d = t1 - t0 - ms(250);
40 // This test is spurious as it depends on the time the thread system switches the threads
41 BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
48 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK
52 boost::this_thread::sleep_for(ms(250));
57 return boost::report_errors();