1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // XFAIL: libcpp-no-exceptions
11 // UNSUPPORTED: libcpp-has-no-threads
12 // UNSUPPORTED: c++98, c++03, c++11
16 // template <class Mutex> class shared_lock;
20 #include <shared_mutex>
23 bool try_lock_called = false;
27 bool try_lock_shared()
29 try_lock_called = !try_lock_called;
30 return try_lock_called;
32 void unlock_shared() {}
40 std::shared_lock<mutex> lk(m, std::defer_lock);
41 assert(lk.try_lock() == true);
42 assert(try_lock_called == true);
43 assert(lk.owns_lock() == true);
49 catch (std::system_error& e)
51 assert(e.code().value() == EDEADLK);
54 assert(lk.try_lock() == false);
55 assert(try_lock_called == false);
56 assert(lk.owns_lock() == false);
63 catch (std::system_error& e)
65 assert(e.code().value() == EPERM);