Debian Codegraph @

libgo/go/runtime/testdata/testprogcgo/crash.go

raw
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "fmt"
9 "runtime"
10 )
11
12 func init() {
13 register("Crash", Crash)
14 }
15
16 var NilPointer *string
17
18 func test(name string) {
19 defer func() {
20 if x := recover(); x != nil {
21 fmt.Printf(" recovered")
22 }
23 fmt.Printf(" done\n")
24 }()
25 fmt.Printf("%s:", name)
26 *NilPointer = name
27 fmt.Print("SHOULD NOT BE HERE")
28 }
29
30 func testInNewThread(name string) {
31 c := make(chan bool)
32 go func() {
33 runtime.LockOSThread()
34 test(name)
35 c <- true
36 }()
37 <-c
38 }
39
40 func Crash() {
41 runtime.LockOSThread()
42 test("main")
43 testInNewThread("new-thread")
44 testInNewThread("second-new-thread")
45 test("main-again")
46 }