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 // lock_guard(mutex_type& m, adopt_lock_t);
16 
17 #include <mutex>
18 #include <cstdlib>
19 #include <cassert>
20 
21 #include "make_test_thread.h"
22 #include "test_macros.h"
23 
24 std::mutex m;
25 
do_try_lock()26 void do_try_lock() {
27   assert(m.try_lock() == false);
28 }
29 
main(int,char **)30 int main(int, char**) {
31   {
32     m.lock();
33     std::lock_guard<std::mutex> lg(m, std::adopt_lock);
34     std::thread t = support::make_test_thread(do_try_lock);
35     t.join();
36   }
37 
38   m.lock();
39   m.unlock();
40 
41   return 0;
42 }
43