-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrw_spinlock_test2.cpp
More file actions
39 lines (33 loc) · 924 Bytes
/
rw_spinlock_test2.cpp
File metadata and controls
39 lines (33 loc) · 924 Bytes
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
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "rw_spinlock.hpp"
#include <boost/core/lightweight_test.hpp>
#include <mutex>
static rw_spinlock sp;
static rw_spinlock sp2;
int main()
{
BOOST_TEST( sp.try_lock() );
BOOST_TEST( !sp.try_lock() );
BOOST_TEST( sp2.try_lock() );
BOOST_TEST( !sp.try_lock() );
BOOST_TEST( !sp2.try_lock() );
sp.unlock();
sp2.unlock();
sp.lock();
BOOST_TEST( !sp.try_lock() );
sp2.lock();
BOOST_TEST( !sp.try_lock() );
BOOST_TEST( !sp2.try_lock() );
sp.unlock();
sp2.unlock();
{
std::lock_guard<rw_spinlock> lock( sp );
BOOST_TEST( !sp.try_lock() );
std::lock_guard<rw_spinlock> lock2( sp2 );
BOOST_TEST( !sp.try_lock() );
BOOST_TEST( !sp2.try_lock() );
}
return boost::report_errors();
}