From ffe7df793adfaf116f25fd335b777e2a74b61da5 Mon Sep 17 00:00:00 2001 From: Marin Tomic Date: Mon, 19 Mar 2018 15:15:17 +0100 Subject: [PATCH] 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 --- src/threading/sync/rwlock.hpp | 3 +-- tests/unit/rwlock.cpp | 47 ----------------------------------- 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/threading/sync/rwlock.hpp b/src/threading/sync/rwlock.hpp index 88838b353..2752b0b64 100644 --- a/src/threading/sync/rwlock.hpp +++ b/src/threading/sync/rwlock.hpp @@ -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 diff --git a/tests/unit/rwlock.cpp b/tests/unit/rwlock.cpp index 030ea8a36..6410931d8 100644 --- a/tests/unit/rwlock.cpp +++ b/tests/unit/rwlock.cpp @@ -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 lock(rwlock); - EXPECT_FALSE(first); - }); - - std::thread t2([&rwlock, &first] { - std::unique_lock 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 lock(rwlock); - EXPECT_FALSE(first); - }); - - std::thread t2([&rwlock, &first] { - std::unique_lock 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.