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 // template <class Mutex> class shared_lock;
16 #include <shared_mutex>
22 #if _LIBCPP_STD_VER > 11
24 std::shared_timed_mutex m;
26 typedef std::chrono::system_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 std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock);
35 time_point t0 = Clock::now();
37 time_point t1 = Clock::now();
38 assert(lk.owns_lock() == true);
39 ns d = t1 - t0 - ms(250);
40 assert(d < ms(25)); // within 25ms
46 catch (std::system_error& e)
48 assert(e.code().value() == EDEADLK);
57 catch (std::system_error& e)
59 assert(e.code().value() == EPERM);
63 #endif // _LIBCPP_STD_VER > 11
67 #if _LIBCPP_STD_VER > 11
69 std::vector<std::thread> v;
70 for (int i = 0; i < 5; ++i)
71 v.push_back(std::thread(f));
72 std::this_thread::sleep_for(ms(250));
76 #endif // _LIBCPP_STD_VER > 11