1 // Copyright (C) 2012 Vicente Botet 2 // 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) 5 6 #define BOOST_THREAD_VERSION 4 7 8 #include <boost/thread/mutex.hpp> 9 #include <boost/thread/lock_traits.hpp> 10 #include <boost/thread/shared_mutex.hpp> 11 #include <boost/thread/strict_lock.hpp> 12 #include <boost/thread/lock_types.hpp> 13 #include <iostream> 14 15 16 BOOST_STATIC_ASSERT(boost::is_strict_lock<boost::strict_lock<boost::mutex> >::value); 17 BOOST_CONCEPT_ASSERT(( boost::BasicLockable<boost::mutex> )); 18 BOOST_CONCEPT_ASSERT(( boost::StrictLock<boost::strict_lock<boost::mutex> > )); 19 main()20int main() 21 { 22 { 23 boost::mutex mtx; 24 boost::strict_lock<boost::mutex> lk(mtx); 25 std::cout << __FILE__ << std::endl; 26 } 27 { 28 boost::timed_mutex mtx; 29 boost::unique_lock<boost::timed_mutex> lk(mtx); 30 boost::nested_strict_lock<boost::unique_lock<boost::timed_mutex> > nlk(lk); 31 std::cout << __FILE__ << std::endl; 32 } 33 { 34 boost::mutex mtx; 35 boost::unique_lock<boost::mutex> lk(mtx, boost::defer_lock); 36 boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk); 37 std::cout << __FILE__ << std::endl; 38 } 39 return 0; 40 } 41