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/lock_types.hpp>
14 #include <boost/thread/strict_lock.hpp>
15 #include <boost/thread/mutex.hpp>
16 #include <boost/thread/thread.hpp>
18 #include <boost/detail/lightweight_test.hpp>
20 #ifdef BOOST_THREAD_USES_CHRONO
21 typedef boost::chrono::high_resolution_clock Clock
;
22 typedef Clock::time_point time_point
;
23 typedef Clock::duration duration
;
24 typedef boost::chrono::milliseconds ms
;
25 typedef boost::chrono::nanoseconds ns
;
30 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO
34 time_point t0
= Clock::now();
36 boost::unique_lock
<boost::mutex
> lg(m
);
38 const auto&& nlg
= boost::make_nested_strict_lock(lg
); (void)nlg
;
41 ns d
= t1
- t0
- ms(250);
42 // This test is spurious as it depends on the time the thread system switches the threads
43 BOOST_TEST(d
< ns(2500000)+ms(1000)); // within 2.5ms
50 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK
54 boost::this_thread::sleep_for(ms(250));
59 return boost::report_errors();