]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: wait for main goroutine before setting GOMAXPROCS.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 5 Mar 2012 21:40:27 +0000 (16:40 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 5 Mar 2012 21:40:27 +0000 (16:40 -0500)
Fixes #3182.

R=golang-dev, dvyukov, rsc
CC=golang-dev, remy
https://golang.org/cl/5732057

src/pkg/runtime/proc.c
src/run.bash

index de7090c527eb28c1f23a15b3df9fbe6cec0f84f3..88e2b61388d3cd630aeda1eb3f60ce069ed5ec50 100644 (file)
@@ -200,7 +200,9 @@ runtime·schedinit(void)
                        n = maxgomaxprocs;
                runtime·gomaxprocs = n;
        }
-       setmcpumax(runtime·gomaxprocs);
+       // wait for the main goroutine to start before taking
+       // GOMAXPROCS into account.
+       setmcpumax(1);
        runtime·singleproc = runtime·gomaxprocs == 1;
 
        canaddmcpu();   // mcpu++ to account for bootstrap m
@@ -225,6 +227,8 @@ runtime·main(void)
        // by calling runtime.LockOSThread during initialization
        // to preserve the lock.
        runtime·LockOSThread();
+       // From now on, newgoroutines may use non-main threads.
+       setmcpumax(runtime·gomaxprocs);
        runtime·sched.init = true;
        scvg = runtime·newproc1((byte*)runtime·MHeap_Scavenger, nil, 0, 0, runtime·main);
        main·init();
index fd3b1f27b7cb3f3f7b31f7a70f86321a28a18695..fdbf47663bbb9b7719588e82adfbf416bd457627 100755 (executable)
@@ -26,8 +26,8 @@ echo '# Testing packages.'
 time go test std -short -timeout=120s
 echo
 
-echo '# runtime -cpu=1,2,4'
-go test runtime -short -timeout=120s -cpu=1,2,4
+echo '# GOMAXPROCS=2 runtime -cpu=1,2,4'
+GOMAXPROCS=2 go test runtime -short -timeout=120s -cpu=1,2,4
 echo
 
 echo '# sync -cpu=10'