[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.lock / thread.lock.shared / thread.lock.shared.cons / mutex_time_point.pass.cpp
blob1fd97b4173e01e4297a5374d254f491b33d83436
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 // UNSUPPORTED: c++03, c++11
12 // <shared_mutex>
14 // class shared_timed_mutex;
16 // template <class Clock, class Duration>
17 // shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
19 #include <thread>
21 #include <atomic>
22 #include <chrono>
23 #include <cassert>
24 #include <cstdlib>
25 #include <shared_mutex>
26 #include <vector>
28 #include "make_test_thread.h"
29 #include "test_macros.h"
31 std::shared_timed_mutex m;
33 typedef std::chrono::steady_clock Clock;
34 typedef Clock::time_point time_point;
35 typedef Clock::duration duration;
36 typedef std::chrono::milliseconds ms;
37 typedef std::chrono::nanoseconds ns;
39 ms LongTime = ms(5000);
40 ms ShortTime = ms(50);
42 static constexpr unsigned Threads = 5;
44 std::atomic<unsigned> CountDown(Threads);
46 void f1()
48 --CountDown;
49 time_point t0 = Clock::now();
50 std::shared_lock<std::shared_timed_mutex> lk(m, t0 + LongTime);
51 time_point t1 = Clock::now();
52 assert(lk.owns_lock() == true);
53 assert(t1 - t0 <= LongTime);
56 void f2()
58 time_point t0 = Clock::now();
59 std::shared_lock<std::shared_timed_mutex> lk(m, t0 + ShortTime);
60 time_point t1 = Clock::now();
61 assert(lk.owns_lock() == false);
62 assert(t1 - t0 >= ShortTime);
65 int main(int, char**)
68 m.lock();
69 std::vector<std::thread> v;
70 for (unsigned i = 0; i < Threads; ++i)
71 v.push_back(support::make_test_thread(f1));
72 while (CountDown > 0)
73 std::this_thread::yield();
74 std::this_thread::sleep_for(ShortTime);
75 m.unlock();
76 for (auto& t : v)
77 t.join();
80 m.lock();
81 std::vector<std::thread> v;
82 for (unsigned i = 0; i < Threads; ++i)
83 v.push_back(support::make_test_thread(f2));
84 for (auto& t : v)
85 t.join();
86 m.unlock();
89 return 0;