[Clang][Sema] Reject declaring an alias template with the same name as its template...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.mutex.requirements / thread.sharedtimedmutex.requirements / thread.sharedtimedmutex.class / try_lock.pass.cpp
blob9ed8b5bb3504148beddddbd2c998c2b31f8b847c
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
12 // <shared_mutex>
14 // class shared_timed_mutex;
16 // bool try_lock();
18 #include <shared_mutex>
19 #include <atomic>
20 #include <cassert>
21 #include <chrono>
22 #include <thread>
24 #include "make_test_thread.h"
26 int main(int, char**) {
27 // Try to exclusive-lock a mutex that is not locked yet. This should succeed.
29 std::shared_timed_mutex m;
30 bool succeeded = m.try_lock();
31 assert(succeeded);
32 m.unlock();
35 // Try to exclusive-lock a mutex that is already locked exclusively. This should fail.
37 std::shared_timed_mutex m;
38 m.lock();
40 std::thread t = support::make_test_thread([&] {
41 bool succeeded = m.try_lock();
42 assert(!succeeded);
43 });
44 t.join();
46 m.unlock();
49 // Try to exclusive-lock a mutex that is already share-locked. This should fail.
51 std::shared_timed_mutex m;
52 m.lock_shared();
54 std::thread t = support::make_test_thread([&] {
55 bool succeeded = m.try_lock();
56 assert(!succeeded);
57 });
58 t.join();
60 m.unlock_shared();
63 return 0;