mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
432ebe13ed
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.
81 lines
1.2 KiB
Go
81 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
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()
|
|
}
|
|
}
|