1
0
mirror of https://github.com/golang/go synced 2024-11-12 00:20:22 -07:00

runtime: wait for main goroutine before setting GOMAXPROCS.

Fixes #3182.

R=golang-dev, dvyukov, rsc
CC=golang-dev, remy
https://golang.org/cl/5732057
This commit is contained in:
Rémy Oudompheng 2012-03-05 16:40:27 -05:00 committed by Russ Cox
parent 610b5b2fd8
commit aa1aaee7fd
2 changed files with 7 additions and 3 deletions

View 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();

View File

@ -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'