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_timed_mutex;
14 // template <class Clock, class Duration>
15 // bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
17 #include <shared_mutex>
22 #if _LIBCPP_STD_VER > 11
24 std::shared_timed_mutex m;
26 typedef std::chrono::steady_clock Clock;
27 typedef Clock::time_point time_point;
28 typedef Clock::duration duration;
29 typedef std::chrono::milliseconds ms;
30 typedef std::chrono::nanoseconds ns;
34 time_point t0 = Clock::now();
35 assert(m.try_lock_until(Clock::now() + ms(300)) == true);
36 time_point t1 = Clock::now();
38 ns d = t1 - t0 - ms(250);
39 assert(d < ms(50)); // within 50ms
44 time_point t0 = Clock::now();
45 assert(m.try_lock_until(Clock::now() + ms(250)) == false);
46 time_point t1 = Clock::now();
47 ns d = t1 - t0 - ms(250);
48 assert(d < ms(50)); // within 50ms
51 #endif // _LIBCPP_STD_VER > 11
55 #if _LIBCPP_STD_VER > 11
59 std::this_thread::sleep_for(ms(250));
66 std::this_thread::sleep_for(ms(300));
70 #endif // _LIBCPP_STD_VER > 11