diff --git a/test/exec/test_bwos_lifo_queue.cpp b/test/exec/test_bwos_lifo_queue.cpp index 3f1f30ea9..a6df5377a 100644 --- a/test/exec/test_bwos_lifo_queue.cpp +++ b/test/exec/test_bwos_lifo_queue.cpp @@ -417,16 +417,20 @@ TEST_CASE("exec::bwos::lifo_queue - steal during wraparound", "[bwos]") constexpr std::size_t blockSize = 4; exec::bwos::lifo_queue queue(numBlocks, blockSize); - std::atomic startStealing{false}; + std::atomic ownerDone{false}; std::atomic stolen{0}; std::thread thief( [&]() { - while (!startStealing) + while (!ownerDone.load(std::memory_order_relaxed)) { - std::this_thread::yield(); + if (queue.steal_front() != 0) + { + stolen++; + } } + // Drain remaining while (queue.steal_front() != 0) { stolen++; @@ -437,18 +441,14 @@ TEST_CASE("exec::bwos::lifo_queue - steal during wraparound", "[bwos]") { for (std::size_t i = 0; i < numBlocks * blockSize; ++i) { - if (!queue.push_back((round * 100) + i + 1)) + while (!queue.push_back((round * 100) + i + 1)) { - startStealing = true; - while (!queue.push_back((round * 100) + i + 1)) - { - std::this_thread::yield(); - } + std::this_thread::yield(); } } } - startStealing = true; + ownerDone = true; thief.join(); } @@ -460,7 +460,7 @@ TEST_CASE("exec::bwos::lifo_queue - takeover grant synchronization", "[bwos]") exec::bwos::lifo_queue queue(numBlocks, blockSize); std::atomic totalStolen{0}; - std::atomic totalPopped{0}; + std::atomic ownerDone{false}; std::thread owner( [&]() @@ -474,20 +474,19 @@ TEST_CASE("exec::bwos::lifo_queue - takeover grant synchronization", "[bwos]") std::this_thread::yield(); } } + // Pop some back (triggers takeover when moving backward across blocks) for (std::size_t i = 0; i < blockSize / 2; ++i) { - if (queue.pop_back() != 0) - { - totalPopped++; - } + queue.pop_back(); } } + ownerDone = true; }); std::thread thief( [&]() { - while (totalPopped < iterations * blockSize / 2) + while (!ownerDone.load(std::memory_order_relaxed)) { if (queue.steal_front() != 0) {