Skip to content

Dont spin main for queue#443

Open
calewis wants to merge 3 commits into
parallaxsw:masterfrom
calewis:dont-spin-main-for-queue
Open

Dont spin main for queue#443
calewis wants to merge 3 commits into
parallaxsw:masterfrom
calewis:dont-spin-main-for-queue

Conversation

@calewis
Copy link
Copy Markdown
Contributor

@calewis calewis commented Jun 2, 2026

Replace the busy-yielding pending_task_count_ loop in DispatchQueue::finishTasks with a blocking DynamicLatch. This avoids having the main thread consume CPU cycles while waiting for dispatched tasks to complete.

The DynamicLatch implementation uses C++20 std::atomic::wait/notify_all for efficient blocking and wakeup. It functions like std::latch except you can also count up with it.

calewis added 3 commits June 2, 2026 16:21
Replace the busy-yielding pending_task_count_ loop in DispatchQueue::finishTasks
with a blocking DynamicLatch. This avoids having the main thread consume CPU
cycles while waiting for dispatched tasks to complete.

The DynamicLatch implementation uses C++20 std::atomic::wait/notify_all for
efficient blocking and wakeup, with proper release-acquire semantics to ensure
task results are visible to the waiting thread.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant