mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1783] runtime: make QueueHolds pump handoff race-free, exception-safe, and per-instance (RT-QUEUE-HOLDS-PUMP-SAFETY) #1797
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1797
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1783
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-queue-holds-pump-safety📝 Commits (2)
3e6e229runtime: make QueueHolds pump handoff race-free, exception-safe, and per-instanceeee02b7runtime: preserve dirty handoff in QueueHolds::pump_ready on exception📊 Changes
3 files changed (+631 additions, -23 deletions)
View changed files
📝
runtime/CMakeLists.txt(+5 -0)📝
runtime/src/queue_holds.h(+85 -23)➕
runtime/test/queue_holds_test.cpp(+541 -0)📄 Description
Summary
Fixes three concurrency/deadlock bugs in
runtime/src/queue_holds.h(the cross-queue Wait-before-Signal and Present barrier scheduler) and adds a standalone portable unit + concurrency stress test suite (runtime/test/queue_holds_test.cpp).RT-QUEUE-HOLDS-PUMP-SAFETYRoot causes
pump_ready():Previously a thread finishing a pump pass executed
pump.unlock()(release) followed bydirty_.load(memory_order_acquire), while a concurrent caller wrotedirty_.store(true, memory_order_release)followed by a failingtry_to_lock(). Under the C++ memory model (and on weakly ordered architectures such as ARM64), a release store followed by an acquire load permits Store-Load reordering: the exiting thread can observedirty_ == falsebefore unlocking while the arriving thread'stry_to_lock()fails before the unlock becomes visible, leaving ready held batches or deferred Presents stalled.in_pump()was manually set totruebeforesnapshot()/discard_waiting_on()/release_ready()/run_barriers()and reset tofalseafterwards. Any thrown exception (e.g.std::bad_allocinsidesnapshot()or a holder/barrier callback) leftin_pump()permanentlytrueon that thread, silently turning all laterpump_ready()andremove_fence()calls on that thread into no-ops.thread_local boolshared acrossQueueHoldsinstances:A nested
pump_ready()orremove_fence()on a secondQueueHoldsinstance while pumping a first instance on the same thread sawin_pump() == trueand returned without pumping or discarding.Changes
runtime/src/queue_holds.h:dirty_andpump_active_under the leafmutex_(preserving strictpump_mutex_->mutex_lock ordering) with an RAIIActiveGuard, eliminating the Store-Load lost-wakeup race.static thread_local boolwith a zero-allocation,noexcept, stack-intrusive RAIIPumpScopechain keyed byconst QueueHolds*, makingin_pump()both exception-safe and per-instance.runtime/test/queue_holds_test.cpp&runtime/CMakeLists.txt:queue_holdsCTest covering cross-queue Wait-before-Signal chains + Present barriers, exception unwinding inrelease_ready()/Barrier::fn/remove_fence(), nested independentQueueHoldsinstances,detach()/cancel_after()synchronization, and a 4-thread high-contention pump handoff stress test (24,000 held ops + 3,000 barriers).Verification
clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/queue_holds_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/queue_holds_test.cpp— pass (zero data races)clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/queue_holds_test.cpp(5 consecutive runs) — 5/5 passqueue_holds_test.cppagainst unpatchedmain:runtime/src/queue_holds.h— fails ontest_exception_safety_does_not_wedge_thread(ran == 1 && !holds.any_held()), confirming regression coveragepython3 -I scripts/check_no_game_data.py runtime/src/queue_holds.h runtime/test/queue_holds_test.cpp runtime/CMakeLists.txt— passpython3 -I tests/test_text_write_line_endings.py— 3/3 pass🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.