Skip to content

Commit e538349

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 3b80621 commit e538349

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
@@ -37,9 +37,18 @@ var (
3737
//
3838
//go:noinline
3939
func deadlock() {
40-
// call yield without requesting a wakeup
40+
exitGoroutine()
41+
}
42+
43+
func exitGoroutine() {
44+
// Pause the goroutine without a way for it to wake up.
45+
// This makes the goroutine unreachable, and should eventually get it
46+
// cleaned up by the GC.
4147
task.Pause()
42-
panic("unreachable")
48+
49+
// We will never return from task.Pause(). Make sure the compiler knows
50+
// this.
51+
trap()
4352
}
4453

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

src/runtime/scheduler_none.go

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func deadlock() {
2929
runtimePanic("all goroutines are asleep - deadlock!")
3030
}
3131

32+
func exitGoroutine() {
33+
// There is only one goroutine, which would exit, so that leads to a
34+
// deadlock.
35+
deadlock()
36+
}
37+
3238
func scheduleTask(t *task.Task) {
3339
// Pause() will panic, so this should not be reachable.
3440
}

0 commit comments

Comments
 (0)