From 6e9fb11b3a314b78f9c2cdb35e3d71a5cce4e06b Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 11 Sep 2018 11:28:24 -0400 Subject: runtime: support disabling goroutine scheduling by class This adds support for disabling the scheduling of user goroutines while allowing system goroutines like the garbage collector to continue running. User goroutines pass through the usual state transitions, but if we attempt to actually schedule one, it will get put on a deferred scheduling list. Updates #26903. This is preparation for unifying STW GC and concurrent GC. Updates #25578. This same mechanism can form the basis for disabling all but a single user goroutine for the purposes of debugger function call injection. Change-Id: Ib72a808e00c25613fe6982f5528160d3de3dbbc6 Reviewed-on: https://go-review.googlesource.com/c/134779 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/runtime2.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/runtime/runtime2.go') diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 259bb376ae..fbca3d3ba6 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -580,6 +580,18 @@ type schedt struct { runq gQueue runqsize int32 + // disable controls selective disabling of the scheduler. + // + // Use schedEnableUser to control this. + // + // disable is protected by sched.lock. + disable struct { + // user disables scheduling of user goroutines. + user bool + runnable gQueue // pending runnable Gs + n int32 // length of runnable + } + // Global cache of dead G's. gFree struct { lock mutex -- cgit v1.3-5-g9baa