File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -3816,8 +3816,10 @@ func injectglist(glist *gList) {
3816
3816
}
3817
3817
3818
3818
npidle := int (sched .npidle .Load ())
3819
- var globq gQueue
3820
- var n int
3819
+ var (
3820
+ globq gQueue
3821
+ n int
3822
+ )
3821
3823
for n = 0 ; n < npidle && ! q .empty (); n ++ {
3822
3824
g := q .pop ()
3823
3825
globq .pushBack (g )
@@ -3833,6 +3835,21 @@ func injectglist(glist *gList) {
3833
3835
if ! q .empty () {
3834
3836
runqputbatch (pp , & q , qsize )
3835
3837
}
3838
+
3839
+ // Some P's might have become idle after we loaded `sched.npidle`
3840
+ // but before any goroutines were added to the queue, which could
3841
+ // lead to idle P's when there is work available in the global queue.
3842
+ // That could potentially last until other goroutines become ready
3843
+ // to run. That said, we need to find a way to hedge
3844
+ //
3845
+ // Calling wakep() here is the best bet, it will do nothing in the
3846
+ // common case (no racing on `sched.npidle`), while it could wake one
3847
+ // more P to execute G's, which might end up with >1 P's: the first one
3848
+ // wakes another P and so forth until there is no more work, but this
3849
+ // ought to be an extremely rare case.
3850
+ //
3851
+ // Also see "Worker thread parking/unparking" comment at the top of the file for details.
3852
+ wakep ()
3836
3853
}
3837
3854
3838
3855
// One round of scheduler: find a runnable goroutine and execute it.
You can’t perform that action at this time.
0 commit comments