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