[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.mutex.requirements / thread.sharedtimedmutex.requirements / thread.sharedtimedmutex.class / try_lock.pass.cpp
blob97fef9b67d8e5ecd79a299beacd81ef6b282bcd0
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: libcpp-has-no-threads
10 // UNSUPPORTED: c++03, c++11
12 // ALLOW_RETRIES: 2
14 // shared_timed_mutex was introduced in macosx10.12
15 // UNSUPPORTED: with_system_cxx_lib=macosx10.11
16 // UNSUPPORTED: with_system_cxx_lib=macosx10.10
17 // UNSUPPORTED: with_system_cxx_lib=macosx10.9
19 // <shared_mutex>
21 // class shared_timed_mutex;
23 // bool try_lock();
25 #include <shared_mutex>
26 #include <thread>
27 #include <cstdlib>
28 #include <cassert>
30 #include "make_test_thread.h"
31 #include "test_macros.h"
33 std::shared_timed_mutex m;
35 typedef std::chrono::system_clock Clock;
36 typedef Clock::time_point time_point;
37 typedef Clock::duration duration;
38 typedef std::chrono::milliseconds ms;
39 typedef std::chrono::nanoseconds ns;
41 void f()
43 time_point t0 = Clock::now();
44 assert(!m.try_lock());
45 assert(!m.try_lock());
46 assert(!m.try_lock());
47 while(!m.try_lock())
49 time_point t1 = Clock::now();
50 m.unlock();
51 ns d = t1 - t0 - ms(250);
52 assert(d < ms(200)); // within 200ms
55 int main(int, char**)
57 m.lock();
58 std::thread t = support::make_test_thread(f);
59 std::this_thread::sleep_for(ms(250));
60 m.unlock();
61 t.join();
63 return 0;