]> Cypherpunks repositories - gostls13.git/commit
runtime: release worldsema before Gosched in STW GC mode
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 22 Nov 2019 16:34:16 +0000 (16:34 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 22 Nov 2019 17:33:48 +0000 (17:33 +0000)
commit05511a5c0ae238325c10b0e4e44c3f66f928e4cf
tree87a477a26da874eee1827dcedbf30de02164be34
parent1c5bd3459b2dfca44e4d313b49b525a26e38c181
runtime: release worldsema before Gosched in STW GC mode

After CL 182657 we no longer hold worldsema across the GC, we hold
gcsema instead.

However in STW GC mode we don't release worldsema before calling Gosched
on the user goroutine (note that user goroutines are disabled during STW
GC) so that user goroutine holds onto it. When the GC is done and the
runtime inevitably wants to "stop the world" again (though there isn't
much to stop) it'll sit there waiting for worldsema which won't be
released until the aforementioned goroutine is scheduled, which it won't
be until the GC is done!

So, we have a deadlock.

The fix is easy: just release worldsema before calling Gosched.

Fixes #34736.

Change-Id: Ia50db22ebed3176114e7e60a7edaf82f8535c1b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/208379
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/mgc.go