-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom-lock.cpp
49 lines (39 loc) · 1.27 KB
/
custom-lock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <boost/ut.hpp>
#include <future>
#include <lockpp/lock.hpp>
using namespace boost::ut;
using namespace boost::ut::bdd;
// NOLINTNEXTLINE
suite<"custom-lock"> custom_lock_suite = []()
{
lockpp::lock<int> test(10);
should("allow shared read") = [&]
{
auto read_1 = test.read();
auto read_2 = test.read();
};
should("allow double unique with adoption") = [&]
{
auto read_1 = test.read<std::unique_lock>();
auto read_2 = test.read<std::unique_lock>(std::adopt_lock);
};
should("deadlock") = [&]
{
std::promise<bool> result;
std::thread thread{[&]
{
try
{
auto read_1 = test.read<std::unique_lock>();
auto read_2 = test.read<std::unique_lock>();
result.set_value(true);
}
catch (...)
{
}
}};
thread.detach();
auto status = result.get_future().wait_for(std::chrono::seconds(5));
expect(status != std::future_status::ready);
};
};