mirror of
https://github.com/golang/go
synced 2024-11-19 05:44:40 -07:00
5695915833
Fixes #2337. Unfortunate sequence of events is: 1. maxcpu=2, mcpu=1, grunning=1 2. starttheworld creates an extra M: maxcpu=2, mcpu=2, grunning=1 4. the goroutine calls runtime.GOMAXPROCS(1) maxcpu=1, mcpu=2, grunning=1 5. since it sees mcpu>maxcpu, it calls gosched() 6. schedule() deschedules the goroutine: maxcpu=1, mcpu=1, grunning=0 7. schedule() call getnextandunlock() which fails to pick up the goroutine again, because canaddcpu() fails, because mcpu==maxcpu 8. then it sees that grunning==0, reports deadlock and terminates R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5191044
19 lines
351 B
Go
19 lines
351 B
Go
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
// 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 main
|
|
|
|
// issue 2337
|
|
// The program deadlocked.
|
|
|
|
import "runtime"
|
|
|
|
func main() {
|
|
runtime.GOMAXPROCS(2)
|
|
runtime.GC()
|
|
runtime.GOMAXPROCS(1)
|
|
}
|