1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: no-threads 10 11 // <mutex> 12 13 // template <class Mutex> class lock_guard; 14 15 // explicit lock_guard(mutex_type& m); 16 17 // template<class _Mutex> lock_guard(lock_guard<_Mutex>) 18 // -> lock_guard<_Mutex>; // C++17 19 20 #include <mutex> 21 #include <cstdlib> 22 #include <cassert> 23 24 #include "make_test_thread.h" 25 #include "test_macros.h" 26 27 std::mutex m; 28 do_try_lock()29void do_try_lock() { 30 assert(m.try_lock() == false); 31 } 32 main(int,char **)33int main(int, char**) { 34 { 35 std::lock_guard<std::mutex> lg(m); 36 std::thread t = support::make_test_thread(do_try_lock); 37 t.join(); 38 } 39 40 m.lock(); 41 m.unlock(); 42 43 #if TEST_STD_VER >= 17 44 std::lock_guard lg(m); 45 static_assert((std::is_same<decltype(lg), std::lock_guard<decltype(m)>>::value), "" ); 46 #endif 47 48 return 0; 49 } 50