4 #include <shared_mutex>
7 #include <condition_variable>
9 std::shared_timed_mutex test_mutex
;
11 std::condition_variable cv
;
13 bool reads_done
= false;
17 auto now
=std::chrono::steady_clock::now();
18 auto then
= now
+ std::chrono::seconds(3);
20 for (i
= 0; i
< 3 && std::chrono::steady_clock::now() < then
; ++i
)
22 if (test_mutex
.try_lock_until(then
))
32 std::cerr
<< "Lock failed\n";
38 auto now
=std::chrono::steady_clock::now();
39 auto then
= now
+ std::chrono::seconds(2);
41 for (i
= 0; i
< 3 && std::chrono::steady_clock::now() < then
; ++i
)
43 if (test_mutex
.try_lock_shared_until(then
))
45 test_mutex
.unlock_shared();
51 std::cerr
<< "Lock shared failed\n";
53 std::unique_lock
<std::mutex
> lock(cv_mutex
);
61 test_mutex
.lock_shared();
65 std::unique_lock
<std::mutex
> lock(cv_mutex
);
71 test_mutex
.unlock_shared();