Skip to content

Commit 4e4e0fb

Browse files
committed
runtime: use exitGoroutine instead of deadlock
This makes the meaning more clear. And while the behavior is currently the same, when we start to use threads we should actually exit the goroutine when calling runtime.Goexit() instead of just leaving it deadlocked.
1 parent febb390 commit 4e4e0fb

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/runtime/panic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ func panicOrGoexit(message interface{}, panicking panicState) {
7171
}
7272
}
7373
if panicking == panicGoexit {
74-
// Call to Goexit() instead of a panic.
74+
// This is a call to Goexit() instead of a panic.
7575
// Exit the goroutine instead of printing a panic message.
76-
deadlock()
76+
exitGoroutine()
7777
}
7878
printstring("panic: ")
7979
printitf(message)

src/runtime/scheduler_cooperative.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ var (
4545
//
4646
//go:noinline
4747
func deadlock() {
48-
// call yield without requesting a wakeup
48+
exitGoroutine()
49+
}
50+
51+
func exitGoroutine() {
52+
// Pause the goroutine without a way for it to wake up.
53+
// This makes the goroutine unreachable, and should eventually get it
54+
// cleaned up by the GC.
4955
task.Pause()
50-
panic("unreachable")
56+
57+
// We will never return from task.Pause(). Make sure the compiler knows
58+
// this.
59+
trap()
5160
}
5261

5362
// Add this task to the end of the run queue.

src/runtime/scheduler_none.go

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func deadlock() {
3636
runtimePanic("all goroutines are asleep - deadlock!")
3737
}
3838

39+
func exitGoroutine() {
40+
// There is only one goroutine, which would exit, so that leads to a
41+
// deadlock.
42+
deadlock()
43+
}
44+
3945
func scheduleTask(t *task.Task) {
4046
// Pause() will panic, so this should not be reachable.
4147
}

0 commit comments

Comments
 (0)