runtime: make Goexit exit host threads

The threads scheduler handled runtime.Goexit using the generic deadlock
path, which parked the current pthread forever. Add a scheduler-specific
goexit hook so it can remove the current task and exit the pthread while
ordinary blocking deadlocks still block.

Track main goroutine Goexit so the last remaining goroutine reports the
expected deadlock instead of letting the process exit successfully.
Expand the crash coverage with the Goexit cases covered by Big Go's
runtime tests.
This commit is contained in:
Jake Bailey
2026-07-03 16:48:11 -07:00
committed by Ron Evans
parent 16eefc59eb
commit 432ebe13ed
14 changed files with 225 additions and 36 deletions
+75 -5
View File
@@ -1,10 +1,80 @@
package main
import "runtime"
import (
"os"
"runtime"
"time"
)
func main() {
defer func() {
panic("panic after Goexit")
}()
runtime.Goexit()
switch os.Args[1] {
case "main":
runtime.Goexit()
case "deadlock":
f := func() {
for i := 0; i < 10; i++ {
}
}
go f()
go f()
runtime.Goexit()
case "exit":
go func() {
time.Sleep(time.Millisecond)
}()
i := 0
runtime.SetFinalizer(&i, func(p *int) {})
runtime.GC()
runtime.Goexit()
case "main-other":
go func() {
println("other goroutine ran")
}()
runtime.Goexit()
case "in-panic":
go func() {
defer func() {
runtime.Goexit()
}()
panic("panic before Goexit")
}()
runtime.Goexit()
case "panic":
defer func() {
panic("panic after Goexit")
}()
runtime.Goexit()
case "recovered-panic":
defer func() {
defer func() {
recover()
}()
panic("recovered panic after Goexit")
}()
runtime.Goexit()
case "recover-before-panic":
defer func() {
if recover() == nil {
panic("bad recover")
}
}()
defer func() {
panic("panic during Goexit")
}()
runtime.Goexit()
case "recover-before-panic-loop":
for i := 0; i < 2; i++ {
defer func() {
}()
}
defer func() {
if recover() == nil {
panic("bad recover")
}
}()
defer func() {
panic("panic during Goexit")
}()
runtime.Goexit()
}
}