1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++98, c++03, c++11
12 
13 // <shared_mutex>
14 
15 // template <class Mutex> class shared_lock;
16 
17 // void unlock();
18 
19 #include <shared_mutex>
20 #include <cassert>
21 
22 bool unlock_called = false;
23 
24 struct mutex
25 {
26     void lock_shared() {}
27     void unlock_shared() {unlock_called = true;}
28 };
29 
30 mutex m;
31 
32 int main()
33 {
34     std::shared_lock<mutex> lk(m);
35     lk.unlock();
36     assert(unlock_called == true);
37     assert(lk.owns_lock() == false);
38     try
39     {
40         lk.unlock();
41         assert(false);
42     }
43     catch (std::system_error& e)
44     {
45         assert(e.code().value() == EPERM);
46     }
47     lk.release();
48     try
49     {
50         lk.unlock();
51         assert(false);
52     }
53     catch (std::system_error& e)
54     {
55         assert(e.code().value() == EPERM);
56     }
57 }
58