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:
Marin Tomic 2018-03-19 15:15:17 +01:00
parent 0b2d0b0d61
commit ffe7df793a
2 changed files with 1 additions and 49 deletions

View File

@ -13,8 +13,7 @@ namespace threading {
/// 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
/// 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
/// held, writers will always be preferred upon it's release.
/// which can lead to reader starvation.
enum RWLockPriority { READ, WRITE };
/// A wrapper around `pthread_rwlock_t`, useful because it is not possible to

View File

@ -52,53 +52,6 @@ TEST(RWLock, SingleWriter) {
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) {
/*
* - Main thread is holding a shared lock until T = 100ms.