]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix GOMAXPROCS vs garbage collection bug
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Apr 2011 16:09:25 +0000 (12:09 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 21 Apr 2011 16:09:25 +0000 (12:09 -0400)
Fixes #1715.

R=golang-dev, rsc1, rsc
CC=golang-dev
https://golang.org/cl/4434053

src/pkg/runtime/proc.c
src/pkg/runtime/proc_test.go [new file with mode: 0644]

index e212c7820fa1f0589c850b157f6398b1c0f98faf..a823dc69287aa0579fc56ce7ec24a724cb202fad 100644 (file)
@@ -1196,6 +1196,12 @@ runtime·gomaxprocsfunc(int32 n)
        if (n <= 0)
                n = ret;
        runtime·gomaxprocs = n;
+       if (runtime·gcwaiting != 0) {
+               if (runtime·sched.mcpumax != 1)
+                       runtime·throw("invalid runtime·sched.mcpumax during gc");
+               schedunlock();
+               return ret;
+       }
        runtime·sched.mcpumax = n;
        // handle fewer procs?
        if(runtime·sched.mcpu > runtime·sched.mcpumax) {
diff --git a/src/pkg/runtime/proc_test.go b/src/pkg/runtime/proc_test.go
new file mode 100644 (file)
index 0000000..f544944
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package runtime_test
+
+import (
+       "runtime"
+       "testing"
+)
+
+func perpetuumMobile() {
+       go perpetuumMobile()
+}
+
+func TestStopTheWorldDeadlock(t *testing.T) {
+       runtime.GOMAXPROCS(3)
+       compl := make(chan int, 1)
+       go func() {
+               for i := 0; i != 1000; i += 1 {
+                       runtime.GC()
+               }
+               compl <- 0
+       }()
+       go func() {
+               for i := 0; i != 1000; i += 1 {
+                       runtime.GOMAXPROCS(3)
+               }
+       }()
+       go perpetuumMobile()
+       <-compl
+}