1
2
3
4
5 package main
6
7 import (
8 "fmt"
9 "runtime"
10 )
11
12 func init() {
13 register("Crash", Crash)
14 }
15
16 func test(name string) {
17 defer func() {
18 if x := recover(); x != nil {
19 fmt.Printf(" recovered")
20 }
21 fmt.Printf(" done\n")
22 }()
23 fmt.Printf("%s:", name)
24 var s *string
25 _ = *s
26 fmt.Print("SHOULD NOT BE HERE")
27 }
28
29 func testInNewThread(name string) {
30 c := make(chan bool)
31 go func() {
32 runtime.LockOSThread()
33 test(name)
34 c <- true
35 }()
36 <-c
37 }
38
39 func Crash() {
40 runtime.LockOSThread()
41 test("main")
42 testInNewThread("new-thread")
43 testInNewThread("second-new-thread")
44 test("main-again")
45 }
46
View as plain text