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, c++14
17 // class shared_mutex;
19 // bool try_lock_shared();
21 #include <shared_mutex>
29 typedef std::chrono::system_clock Clock;
30 typedef Clock::time_point time_point;
31 typedef Clock::duration duration;
32 typedef std::chrono::milliseconds ms;
33 typedef std::chrono::nanoseconds ns;
37 time_point t0 = Clock::now();
38 assert(!m.try_lock_shared());
39 assert(!m.try_lock_shared());
40 assert(!m.try_lock_shared());
41 while(!m.try_lock_shared())
43 time_point t1 = Clock::now();
45 ns d = t1 - t0 - ms(250);
46 assert(d < ms(200)); // within 200ms
53 std::vector<std::thread> v;
54 for (int i = 0; i < 5; ++i)
55 v.push_back(std::thread(f));
56 std::this_thread::sleep_for(ms(250));