mirror of
https://github.com/golang/go
synced 2024-11-22 05:34:39 -07:00
runtime: restore deadlock detection in the simplest case.
Fixes #3342. R=iant, r, dave, rsc CC=golang-dev, remy https://golang.org/cl/5844051
This commit is contained in:
parent
603a44c50f
commit
84bb2547fb
@ -358,6 +358,9 @@ runtime·MHeap_Scavenger(void)
|
||||
|
||||
h = &runtime·mheap;
|
||||
for(k=0;; k++) {
|
||||
// Return to the scheduler in case the rest of the world is deadlocked.
|
||||
runtime·gosched();
|
||||
|
||||
runtime·noteclear(¬e);
|
||||
runtime·entersyscall();
|
||||
runtime·notetsleep(¬e, tick);
|
||||
|
@ -521,6 +521,16 @@ mnextg(M *m, G *g)
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a deadlock situation.
|
||||
static void
|
||||
checkdeadlock(void) {
|
||||
if((scvg == nil && runtime·sched.grunning == 0) ||
|
||||
(scvg != nil && runtime·sched.grunning == 1 && runtime·sched.gwait == 0 &&
|
||||
(scvg->status == Grunnable || scvg->status == Grunning || scvg->status == Gsyscall))) {
|
||||
runtime·throw("all goroutines are asleep - deadlock!");
|
||||
}
|
||||
}
|
||||
|
||||
// Get the next goroutine that m should run.
|
||||
// Sched must be locked on entry, is unlocked on exit.
|
||||
// Makes sure that at most $GOMAXPROCS g's are
|
||||
@ -570,6 +580,9 @@ top:
|
||||
continue;
|
||||
}
|
||||
runtime·sched.grunning++;
|
||||
// The work could actually have been the sole scavenger
|
||||
// goroutine. Look for deadlock situation.
|
||||
checkdeadlock();
|
||||
schedunlock();
|
||||
return gp;
|
||||
}
|
||||
@ -591,11 +604,7 @@ top:
|
||||
}
|
||||
|
||||
// Look for deadlock situation.
|
||||
if((scvg == nil && runtime·sched.grunning == 0) ||
|
||||
(scvg != nil && runtime·sched.grunning == 1 && runtime·sched.gwait == 0 &&
|
||||
(scvg->status == Grunning || scvg->status == Gsyscall))) {
|
||||
runtime·throw("all goroutines are asleep - deadlock!");
|
||||
}
|
||||
checkdeadlock();
|
||||
|
||||
m->nextg = nil;
|
||||
m->waitnextg = 1;
|
||||
|
13
test/fixedbugs/bug429.go
Normal file
13
test/fixedbugs/bug429.go
Normal file
@ -0,0 +1,13 @@
|
||||
// $G $D/$F.go && $L $F.$A && ! ./$A.out || echo BUG: bug429
|
||||
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Should print deadlock message, not hang.
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
select{}
|
||||
}
|
@ -15,6 +15,9 @@
|
||||
|
||||
== fixedbugs/
|
||||
|
||||
=========== fixedbugs/bug429.go
|
||||
throw: all goroutines are asleep - deadlock!
|
||||
|
||||
== bugs/
|
||||
|
||||
=========== bugs/bug395.go
|
||||
|
Loading…
Reference in New Issue
Block a user