mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: fix program termination when main goroutine calls Goexit
Do not consider idle finalizer/bgsweep/timer goroutines as doing something useful. We can't simply set isbackground for the whole lifetime of the goroutines, because when finalizer goroutine calls user function, we do want to consider it as doing something useful. This is borken due to timers for quite some time. With background sweep is become even more broken. Fixes #7784. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/87960044
This commit is contained in:
parent
d826b2ed98
commit
55e0f36fb4
3 changed files with 34 additions and 0 deletions
|
|
@ -144,6 +144,15 @@ panic: again
|
|||
|
||||
}
|
||||
|
||||
func TestGoexitExit(t *testing.T) {
|
||||
output := executeTest(t, goexitExitSource, nil)
|
||||
want := ""
|
||||
if output != want {
|
||||
t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const crashSource = `
|
||||
package main
|
||||
|
||||
|
|
@ -310,3 +319,22 @@ func main() {
|
|||
panic("again")
|
||||
}
|
||||
`
|
||||
|
||||
const goexitExitSource = `
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond)
|
||||
}()
|
||||
i := 0
|
||||
runtime.SetFinalizer(&i, func(p *int) {})
|
||||
runtime.GC()
|
||||
runtime.Goexit()
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue