@@ -417,16 +417,20 @@ TEST_CASE("exec::bwos::lifo_queue - steal during wraparound", "[bwos]")
417417 constexpr std::size_t blockSize = 4 ;
418418
419419 exec::bwos::lifo_queue<std::size_t > queue (numBlocks, blockSize);
420- std::atomic<bool > startStealing {false };
420+ std::atomic<bool > ownerDone {false };
421421 std::atomic<std::size_t > stolen{0 };
422422
423423 std::thread thief (
424424 [&]()
425425 {
426- while (!startStealing )
426+ while (!ownerDone. load (std::memory_order_relaxed) )
427427 {
428- std::this_thread::yield ();
428+ if (queue.steal_front () != 0 )
429+ {
430+ stolen++;
431+ }
429432 }
433+ // Drain remaining
430434 while (queue.steal_front () != 0 )
431435 {
432436 stolen++;
@@ -437,18 +441,14 @@ TEST_CASE("exec::bwos::lifo_queue - steal during wraparound", "[bwos]")
437441 {
438442 for (std::size_t i = 0 ; i < numBlocks * blockSize; ++i)
439443 {
440- if (!queue.push_back ((round * 100 ) + i + 1 ))
444+ while (!queue.push_back ((round * 100 ) + i + 1 ))
441445 {
442- startStealing = true ;
443- while (!queue.push_back ((round * 100 ) + i + 1 ))
444- {
445- std::this_thread::yield ();
446- }
446+ std::this_thread::yield ();
447447 }
448448 }
449449 }
450450
451- startStealing = true ;
451+ ownerDone = true ;
452452 thief.join ();
453453}
454454
@@ -460,7 +460,7 @@ TEST_CASE("exec::bwos::lifo_queue - takeover grant synchronization", "[bwos]")
460460
461461 exec::bwos::lifo_queue<std::size_t > queue (numBlocks, blockSize);
462462 std::atomic<std::size_t > totalStolen{0 };
463- std::atomic<std:: size_t > totalPopped{ 0 };
463+ std::atomic<bool > ownerDone{ false };
464464
465465 std::thread owner (
466466 [&]()
@@ -474,20 +474,19 @@ TEST_CASE("exec::bwos::lifo_queue - takeover grant synchronization", "[bwos]")
474474 std::this_thread::yield ();
475475 }
476476 }
477+ // Pop some back (triggers takeover when moving backward across blocks)
477478 for (std::size_t i = 0 ; i < blockSize / 2 ; ++i)
478479 {
479- if (queue.pop_back () != 0 )
480- {
481- totalPopped++;
482- }
480+ queue.pop_back ();
483481 }
484482 }
483+ ownerDone = true ;
485484 });
486485
487486 std::thread thief (
488487 [&]()
489488 {
490- while (totalPopped < iterations * blockSize / 2 )
489+ while (!ownerDone. load (std::memory_order_relaxed) )
491490 {
492491 if (queue.steal_front () != 0 )
493492 {
0 commit comments