15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier //
9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // <mutex>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template <class Mutex> class lock_guard;
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // lock_guard(mutex_type& m, adopt_lock_t);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <mutex>
185a83710eSEric Fiselier #include <cstdlib>
195a83710eSEric Fiselier #include <cassert>
205a83710eSEric Fiselier 
2178036360SIgor Kudrin #include "make_test_thread.h"
227fc6a556SMarshall Clow #include "test_macros.h"
237fc6a556SMarshall Clow 
245a83710eSEric Fiselier std::mutex m;
255a83710eSEric Fiselier 
do_try_lock()2678036360SIgor Kudrin void do_try_lock() {
2778036360SIgor Kudrin   assert(m.try_lock() == false);
2878036360SIgor Kudrin }
2978036360SIgor Kudrin 
main(int,char **)30504bc07dSLouis Dionne int main(int, char**) {
315a83710eSEric Fiselier   {
325a83710eSEric Fiselier     m.lock();
335a83710eSEric Fiselier     std::lock_guard<std::mutex> lg(m, std::adopt_lock);
3478036360SIgor Kudrin     std::thread t = support::make_test_thread(do_try_lock);
3578036360SIgor Kudrin     t.join();
365a83710eSEric Fiselier   }
375a83710eSEric Fiselier 
385a83710eSEric Fiselier   m.lock();
395a83710eSEric Fiselier   m.unlock();
402df59c50SJF Bastien 
412df59c50SJF Bastien   return 0;
425a83710eSEric Fiselier }
43