Repository navigation
Thread pool: spawn threads in dispatch() - #1786
Merged
Merged
Conversation
dispatch() enqueued the task and called notify_one(), but never called spawn_threads(). Since all of the global pools start with zero threads, a plain dispatch() on a cold pool woke no one and the task never ran. On a pool with fewer threads than its maximum, the pool also never grew to use the headroom. dispatch_now_blocking(), try_dispatch_now() and run_in_parallel() all call spawn_threads(), so only the plain dispatch() path was affected. Call spawn_threads() after the task is enqueued, the same as the other entry points.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
ThreadPool_Default::dispatch()never growing the thread pool.The bug
dispatch()enqueued the task and calledm_thread_cv.notify_one(), but never calledspawn_threads(). Since all of the global pools inGlobalThreadPools.cppstart with zero threads, a plaindispatch()on a cold pool had no waiter to wake - the task sat in the queue and never ran. On a pool with fewer live threads than its maximum, the pool also never used its headroom.dispatch_now_blocking(),try_dispatch_now()andrun_in_parallel()all callspawn_threads(), so only the plaindispatch()path was affected.The fix
Call
spawn_threads()after the task is enqueued (under the lock), the same as the other entry points.Testing
Standalone functional test against
ThreadPool_Default:dispatch()on a 0-thread pool now runs (previously it hung forever),dispatch_now_blocking()/try_dispatch_now()still work.pa-build+pa-testgreen.