summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2023-07-10 13:19:20 +0200
committerGitHub <noreply@github.com>2023-07-10 13:19:20 +0200
commit566acc84e1dc2cf56973f8721136e7255ca5a8cc (patch)
treea9a98b4d0a890b9c749c63e8decf7201be6b96b7
parent515f12609240b6d6bd99707c0fd5bcbfa91e8e0e (diff)
parent0c654b649fd5797da992398d9ba56435fae3f123 (diff)
Merge pull request #27720 from vespa-engine/toregge/avoid-livelock-when-running-rcu-vector-unit-test-with-valgrind
Avoid livelock when running rcu vector unit test with valgrind.
-rw-r--r--vespalib/src/tests/util/rcuvector/rcuvector_test.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp
index b842d009ce8..2c5af5c02ec 100644
--- a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp
+++ b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp
@@ -10,6 +10,7 @@
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <random>
+#include <thread>
using namespace vespalib;
@@ -20,6 +21,18 @@ using vespalib::makeLambdaTask;
using MyMemoryAllocator = vespalib::alloc::test::MemoryAllocatorObserver;
using AllocStats = MyMemoryAllocator::Stats;
+namespace {
+
+void consider_yield(uint32_t i)
+{
+ if ((i % 1111) == 0) {
+ // Need to yield sometimes to avoid livelock when running unit test with valgrind
+ std::this_thread::yield();
+ }
+}
+
+}
+
bool
assertUsage(const MemoryUsage & exp, const MemoryUsage & act)
{
@@ -452,12 +465,15 @@ StressFixture::read_work()
std::mt19937 gen(rd());
std::uniform_int_distribution<uint32_t> distrib(0, read_area - 1);
std::vector<int> old(read_area);
+ uint32_t i = 0;
while (!stop_read.load(std::memory_order_relaxed)) {
uint32_t idx = distrib(gen);
auto guard = generation_handler.takeGuard();
int value = arr.acquire_elem_ref(idx).load_acquire();
EXPECT_LE(old[idx], value);
old[idx] = value;
+ consider_yield(i);
+ ++i;
}
}
@@ -478,6 +494,7 @@ StressFixture::write_work(uint32_t cnt)
uint32_t idx = distrib(gen);
arr[idx].store_release(arr[idx].load_relaxed() + 1);
commit();
+ consider_yield(i);
}
}