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