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 // mutex_type* release() noexcept;
18 
19 #include <shared_mutex>
20 #include <cassert>
21 
22 struct mutex
23 {
24     static int lock_count;
25     static int unlock_count;
lock_sharedmutex26     void lock_shared() {++lock_count;}
unlock_sharedmutex27     void unlock_shared() {++unlock_count;}
28 };
29 
30 int mutex::lock_count = 0;
31 int mutex::unlock_count = 0;
32 
33 mutex m;
34 
main()35 int main()
36 {
37     std::shared_lock<mutex> lk(m);
38     assert(lk.mutex() == &m);
39     assert(lk.owns_lock() == true);
40     assert(mutex::lock_count == 1);
41     assert(mutex::unlock_count == 0);
42     assert(lk.release() == &m);
43     assert(lk.mutex() == nullptr);
44     assert(lk.owns_lock() == false);
45     assert(mutex::lock_count == 1);
46     assert(mutex::unlock_count == 0);
47     static_assert(noexcept(lk.release()), "release must be noexcept");
48 }
49