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
14 // template <class Mutex> class shared_lock;
16 // explicit shared_lock(mutex_type& m);
18 #include <shared_mutex>
24 #if _LIBCPP_STD_VER > 11
26 std::shared_timed_mutex m;
28 typedef std::chrono::system_clock Clock;
29 typedef Clock::time_point time_point;
30 typedef Clock::duration duration;
31 typedef std::chrono::milliseconds ms;
32 typedef std::chrono::nanoseconds ns;
36 time_point t0 = Clock::now();
39 std::shared_lock<std::shared_timed_mutex> ul(m);
42 ns d = t1 - t0 - ms(250);
43 assert(d < ms(50)); // within 50ms
48 time_point t0 = Clock::now();
51 std::shared_lock<std::shared_timed_mutex> ul(m);
55 assert(d < ms(50)); // within 50ms
58 #endif // _LIBCPP_STD_VER > 11
62 #if _LIBCPP_STD_VER > 11
64 std::vector<std::thread> v;
65 for (int i = 0; i < 5; ++i)
66 v.push_back(std::thread(f));
67 std::this_thread::sleep_for(ms(250));
75 std::this_thread::sleep_for(ms(250));
80 #endif // _LIBCPP_STD_VER > 11