Debian Codegraph @

libgo/misc/cgo/testcshared/testdata/libgo4/libgo4.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 "C"
8
9 import (
10 "fmt"
11 "os"
12 "runtime"
13 )
14
15 // RunGoroutines starts some goroutines that don't do anything.
16 // The idea is to get some threads going, so that a signal will be delivered
17 // to a thread started by Go.
18 //export RunGoroutines
19 func RunGoroutines() {
20 for i := 0; i < 4; i++ {
21 go func() {
22 runtime.LockOSThread()
23 select {}
24 }()
25 }
26 }
27
28 var P *byte
29
30 // TestSEGV makes sure that an invalid address turns into a run-time Go panic.
31 //export TestSEGV
32 func TestSEGV() {
33 defer func() {
34 if recover() == nil {
35 fmt.Fprintln(os.Stderr, "no panic from segv")
36 os.Exit(1)
37 }
38 }()
39 *P = 0
40 fmt.Fprintln(os.Stderr, "continued after segv")
41 os.Exit(1)
42 }
43
44 func main() {
45 }