From 84a991a8a64263f46bdbe5cef0f82b520b07560f Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 12 Feb 2024 01:09:33 +0100 Subject: [PATCH] fix --- .../test/LockFreeForwardListTest.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/multi-threaded/test/LockFreeForwardListTest.cpp b/src/multi-threaded/test/LockFreeForwardListTest.cpp index 4e2720e4..ef6ffb19 100644 --- a/src/multi-threaded/test/LockFreeForwardListTest.cpp +++ b/src/multi-threaded/test/LockFreeForwardListTest.cpp @@ -52,24 +52,26 @@ TEST(LockFreeListTest, concurrent_push) { TEST(LockFreeListTest, push_while_looping) { LockFreeForwardList list{"foo", "bla"}; - std::size_t times = 50; + std::size_t insertions = 40; - std::atomic_bool producing = true; - std::size_t max_size = 0; + std::atomic_bool barrier = true; + std::size_t list_snapshot_size; ParallelRegion::execute( [&] { - for (std::size_t k = 0; k < times; ++k) { + for (std::size_t k = 0; k < insertions / 2; ++k) { + list.emplace_back("foo", "bla"); + } + barrier = false; + for (std::size_t k = 0; k < insertions / 2; ++k) { list.emplace_back("foo", "bla"); } - producing = false; }, [&] { - while (producing.load()) { - std::size_t size = 0; - list.forEach([&](const Person &person) { ++size; }); - max_size = std::max(max_size, size); + while (barrier.load()) { } + std::size_t size = 0; + list.forEach([&](const Person &person) { ++list_snapshot_size; }); }); - EXPECT_TRUE(40 < max_size); + EXPECT_TRUE(insertions / 2 <= list_snapshot_size); }