Remove writers preference test for RWLock
Summary: Writers preference is not guaranteed by the standard and as such there are variations between implementations in different versions of libphthread. Reviewers: dgleich Reviewed By: dgleich Differential Revision: https://phabricator.memgraph.io/D1305
This commit is contained in:
parent
0b2d0b0d61
commit
ffe7df793a
@ -13,8 +13,7 @@ namespace threading {
|
|||||||
/// though there is a thread waiting for an exclusive (write) lock, which can
|
/// though there is a thread waiting for an exclusive (write) lock, which can
|
||||||
/// lead to writer starvation. If the priority is set to `WRITE`, readers will
|
/// lead to writer starvation. If the priority is set to `WRITE`, readers will
|
||||||
/// be blocked from obtaining new shared locks while there are writers waiting,
|
/// be blocked from obtaining new shared locks while there are writers waiting,
|
||||||
/// which can lead to reader starvation. However, if there is an exclusive lock
|
/// which can lead to reader starvation.
|
||||||
/// held, writers will always be preferred upon it's release.
|
|
||||||
enum RWLockPriority { READ, WRITE };
|
enum RWLockPriority { READ, WRITE };
|
||||||
|
|
||||||
/// A wrapper around `pthread_rwlock_t`, useful because it is not possible to
|
/// A wrapper around `pthread_rwlock_t`, useful because it is not possible to
|
||||||
|
@ -52,53 +52,6 @@ TEST(RWLock, SingleWriter) {
|
|||||||
EXPECT_GE(timer.Elapsed(), 290ms);
|
EXPECT_GE(timer.Elapsed(), 290ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next two tests demonstrate that writers are always preferred when an unique
|
|
||||||
* lock is released. */
|
|
||||||
|
|
||||||
TEST(RWLock, WritersPreferred_1) {
|
|
||||||
RWLock rwlock(RWLockPriority::READ);
|
|
||||||
rwlock.lock();
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
std::thread t1([&rwlock, &first] {
|
|
||||||
std::shared_lock<RWLock> lock(rwlock);
|
|
||||||
EXPECT_FALSE(first);
|
|
||||||
});
|
|
||||||
|
|
||||||
std::thread t2([&rwlock, &first] {
|
|
||||||
std::unique_lock<RWLock> lock(rwlock);
|
|
||||||
EXPECT_TRUE(first);
|
|
||||||
first = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(100ms);
|
|
||||||
rwlock.unlock();
|
|
||||||
t1.join();
|
|
||||||
t2.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RWLock, WritersPreferred_2) {
|
|
||||||
RWLock rwlock(RWLockPriority::WRITE);
|
|
||||||
rwlock.lock();
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
std::thread t1([&rwlock, &first] {
|
|
||||||
std::shared_lock<RWLock> lock(rwlock);
|
|
||||||
EXPECT_FALSE(first);
|
|
||||||
});
|
|
||||||
|
|
||||||
std::thread t2([&rwlock, &first] {
|
|
||||||
std::unique_lock<RWLock> lock(rwlock);
|
|
||||||
EXPECT_TRUE(first);
|
|
||||||
first = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(100ms);
|
|
||||||
rwlock.unlock();
|
|
||||||
t1.join();
|
|
||||||
t2.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RWLock, ReadPriority) {
|
TEST(RWLock, ReadPriority) {
|
||||||
/*
|
/*
|
||||||
* - Main thread is holding a shared lock until T = 100ms.
|
* - Main thread is holding a shared lock until T = 100ms.
|
||||||
|
Loading…
Reference in New Issue
Block a user