owns_lock_pass.cpp 924 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2012 Vicente J. Botet Escriba
  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. // <boost/thread/locks.hpp>
  6. // template <class Mutex> class strict_lock;
  7. // bool owns_lock(Mutex *) const;
  8. #include <boost/thread/strict_lock.hpp>
  9. #include <boost/thread/mutex.hpp>
  10. #include <boost/thread/thread.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #ifdef BOOST_THREAD_USES_CHRONO
  13. typedef boost::chrono::high_resolution_clock Clock;
  14. typedef Clock::time_point time_point;
  15. typedef Clock::duration duration;
  16. typedef boost::chrono::milliseconds ms;
  17. typedef boost::chrono::nanoseconds ns;
  18. #endif
  19. int main()
  20. {
  21. boost::mutex m;
  22. boost::mutex m2;
  23. boost::strict_lock<boost::mutex> lk(m);
  24. BOOST_TEST(lk.owns_lock(&m) == true);
  25. BOOST_TEST(!lk.owns_lock(&m2) == true);
  26. return boost::report_errors();
  27. }