1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
14 // class shared_timed_mutex;
16 // bool try_lock_shared();
18 #include <shared_mutex>
23 #include "make_test_thread.h"
25 int main(int, char**) {
26 // Try to lock-shared a mutex that is not locked yet. This should succeed.
28 std::shared_timed_mutex m
;
29 std::vector
<std::thread
> threads
;
30 for (int i
= 0; i
!= 5; ++i
) {
31 threads
.push_back(support::make_test_thread([&] {
32 bool succeeded
= m
.try_lock_shared();
38 for (auto& t
: threads
)
42 // Try to lock-shared a mutex that is already exclusively locked. This should fail.
44 std::shared_timed_mutex m
;
47 std::vector
<std::thread
> threads
;
48 for (int i
= 0; i
!= 5; ++i
) {
49 threads
.push_back(support::make_test_thread([&] {
50 bool succeeded
= m
.try_lock_shared();
55 for (auto& t
: threads
)
61 // Try to lock-shared a mutex that is already lock-shared. This should succeed.
63 std::shared_timed_mutex m
;
65 std::vector
<std::thread
> threads
;
66 for (int i
= 0; i
!= 5; ++i
) {
67 threads
.push_back(support::make_test_thread([&] {
68 bool succeeded
= m
.try_lock_shared();
75 for (auto& t
: threads
)