runtime: goexit use thread key

This commit is contained in:
visualfc
2025-02-16 19:53:38 +08:00
parent 51755b8da3
commit 8591275eb2
3 changed files with 68 additions and 9 deletions

View File

@@ -0,0 +1,57 @@
package main
import (
"runtime"
)
func main() {
demo1()
demo2()
demo3()
}
func demo1() {
ch := make(chan bool)
go func() {
defer func() {
ch <- true
}()
runtime.Goexit()
}()
<-ch
}
func demo2() {
ch := make(chan bool)
go func() {
defer func() {
if r := recover(); r != nil {
panic("must nil")
}
ch <- true
}()
runtime.Goexit()
}()
<-ch
}
func demo3() {
ch := make(chan bool)
go func() {
defer func() {
r := recover()
if r != "error" {
panic("must error")
}
ch <- true
}()
defer func() {
if r := recover(); r != nil {
panic("must nil")
}
panic("error")
}()
runtime.Goexit()
}()
<-ch
}

View File

@@ -0,0 +1 @@
;