1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++03, c++98, c++11
17 // class shared_timed_mutex;
19 // bool try_lock_shared();
21 #include <shared_mutex>
27 #include "test_macros.h"
29 std::shared_timed_mutex m;
31 typedef std::chrono::system_clock Clock;
32 typedef Clock::time_point time_point;
33 typedef Clock::duration duration;
34 typedef std::chrono::milliseconds ms;
35 typedef std::chrono::nanoseconds ns;
38 #if !defined(TEST_HAS_SANITIZERS)
39 ms Tolerance = ms(200);
41 ms Tolerance = ms(200 * 5);
46 time_point t0 = Clock::now();
47 assert(!m.try_lock_shared());
48 assert(!m.try_lock_shared());
49 assert(!m.try_lock_shared());
50 while(!m.try_lock_shared())
52 time_point t1 = Clock::now();
54 ns d = t1 - t0 - ms(250);
55 assert(d < Tolerance); // within tolerance
61 std::vector<std::thread> v;
62 for (int i = 0; i < 5; ++i)
63 v.push_back(std::thread(f));
64 std::this_thread::sleep_for(ms(250));