...

Source file src/cmd/cgo/internal/testcshared/testdata/libgo4/libgo4.go

Documentation: cmd/cgo/internal/testcshared/testdata/libgo4

     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  //
    19  //export RunGoroutines
    20  func RunGoroutines() {
    21  	for i := 0; i < 4; i++ {
    22  		go func() {
    23  			runtime.LockOSThread()
    24  			select {}
    25  		}()
    26  	}
    27  }
    28  
    29  var P *byte
    30  
    31  // TestSEGV makes sure that an invalid address turns into a run-time Go panic.
    32  //
    33  //export TestSEGV
    34  func TestSEGV() {
    35  	defer func() {
    36  		if recover() == nil {
    37  			fmt.Fprintln(os.Stderr, "no panic from segv")
    38  			os.Exit(1)
    39  		}
    40  	}()
    41  	*P = 0
    42  	fmt.Fprintln(os.Stderr, "continued after segv")
    43  	os.Exit(1)
    44  }
    45  
    46  func main() {
    47  }
    48  

View as plain text