Source file
test/fixedbugs/issue24491b.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "runtime"
14 "unsafe"
15 )
16
17 var done = make(chan bool)
18
19 func setup() unsafe.Pointer {
20 s := "ok"
21 runtime.SetFinalizer(&s, func(p *string) { close(done) })
22 return unsafe.Pointer(&s)
23 }
24
25
26
27 func before(p uintptr) int {
28 runtime.GC()
29 select {
30 case <-done:
31 panic("GC early")
32 default:
33 }
34 return 0
35 }
36
37 func after() int {
38 runtime.GC()
39 runtime.GC()
40 <-done
41 return 0
42 }
43
44 func main() {
45 _ = before(uintptr(setup())) + after()
46 }
47
View as plain text