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 //===----------------------------------------------------------------------===//
12 // class shared_mutex;
14 // template <class Clock, class Duration>
15 // shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
17 #include <shared_mutex>
23 #if _LIBCPP_STD_VER > 11
27 typedef std::chrono::steady_clock Clock;
28 typedef Clock::time_point time_point;
29 typedef Clock::duration duration;
30 typedef std::chrono::milliseconds ms;
31 typedef std::chrono::nanoseconds ns;
35 time_point t0 = Clock::now();
36 std::shared_lock<std::shared_mutex> lk(m, Clock::now() + ms(300));
37 assert(lk.owns_lock() == true);
38 time_point t1 = Clock::now();
39 ns d = t1 - t0 - ms(250);
40 assert(d < ns(50000000)); // within 50ms
45 time_point t0 = Clock::now();
46 std::shared_lock<std::shared_mutex> lk(m, Clock::now() + ms(250));
47 assert(lk.owns_lock() == false);
48 time_point t1 = Clock::now();
49 ns d = t1 - t0 - ms(250);
50 assert(d < ms(50)); // within 50ms
53 #endif // _LIBCPP_STD_VER > 11
57 #if _LIBCPP_STD_VER > 11
60 std::vector<std::thread> v;
61 for (int i = 0; i < 5; ++i)
62 v.push_back(std::thread(f1));
63 std::this_thread::sleep_for(ms(250));
70 std::vector<std::thread> v;
71 for (int i = 0; i < 5; ++i)
72 v.push_back(std::thread(f2));
73 std::this_thread::sleep_for(ms(300));
78 #endif // _LIBCPP_STD_VER > 11