[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.mutex.requirements / thread.sharedtimedmutex.requirements / thread.sharedtimedmutex.class / try_lock_shared.pass.cpp
blob8523df08f81294ad478f708e2148203f02b54333
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 // ALLOW_RETRIES: 2
14 // <shared_mutex>
16 // class shared_timed_mutex;
18 // bool try_lock_shared();
20 #include <cassert>
21 #include <chrono>
22 #include <cstdlib>
23 #include <shared_mutex>
24 #include <thread>
25 #include <vector>
27 #include "make_test_thread.h"
28 #include "test_macros.h"
30 std::shared_timed_mutex m;
32 typedef std::chrono::system_clock Clock;
33 typedef Clock::time_point time_point;
34 typedef Clock::duration duration;
35 typedef std::chrono::milliseconds ms;
36 typedef std::chrono::nanoseconds ns;
39 // Thread sanitizer causes more overhead and will sometimes cause this test
40 // to fail. To prevent this we give Thread sanitizer more time to complete the
41 // test.
42 #if !defined(TEST_IS_EXECUTED_IN_A_SLOW_ENVIRONMENT)
43 ms Tolerance = ms(200);
44 #else
45 ms Tolerance = ms(200 * 5);
46 #endif
48 void f()
50 time_point t0 = Clock::now();
51 assert(!m.try_lock_shared());
52 assert(!m.try_lock_shared());
53 assert(!m.try_lock_shared());
54 while(!m.try_lock_shared())
55 std::this_thread::yield();
56 time_point t1 = Clock::now();
57 m.unlock_shared();
58 ns d = t1 - t0 - ms(250);
59 assert(d < Tolerance); // within tolerance
62 int main(int, char**)
64 m.lock();
65 std::vector<std::thread> v;
66 for (int i = 0; i < 5; ++i)
67 v.push_back(support::make_test_thread(f));
68 std::this_thread::sleep_for(ms(250));
69 m.unlock();
70 for (auto& t : v)
71 t.join();
73 return 0;