Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Foo committed Feb 12, 2024
1 parent 2b47c5e commit 84a991a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/multi-threaded/test/LockFreeForwardListTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,26 @@ TEST(LockFreeListTest, concurrent_push) {

TEST(LockFreeListTest, push_while_looping) {
LockFreeForwardList<Person> 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<std::size_t>(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);
}

0 comments on commit 84a991a

Please sign in to comment.