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 // XFAIL: libcpp-no-exceptions 11 // UNSUPPORTED: libcpp-has-no-threads 12 // UNSUPPORTED: c++98, c++03, c++11 13 14 // <shared_mutex> 15 16 // template <class Mutex> class shared_lock; 17 18 // void unlock(); 19 20 #include <shared_mutex> 21 #include <cassert> 22 23 bool unlock_called = false; 24 25 struct mutex 26 { 27 void lock_shared() {} 28 void unlock_shared() {unlock_called = true;} 29 }; 30 31 mutex m; 32 33 int main() 34 { 35 std::shared_lock<mutex> lk(m); 36 lk.unlock(); 37 assert(unlock_called == true); 38 assert(lk.owns_lock() == false); 39 try 40 { 41 lk.unlock(); 42 assert(false); 43 } 44 catch (std::system_error& e) 45 { 46 assert(e.code().value() == EPERM); 47 } 48 lk.release(); 49 try 50 { 51 lk.unlock(); 52 assert(false); 53 } 54 catch (std::system_error& e) 55 { 56 assert(e.code().value() == EPERM); 57 } 58 } 59