rsc.io/go@v0.0.0-20150416155037-e040fd465409/misc/cgo/testcarchive/src/libgo/libgo.go (about) 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 _ "p" 9 "syscall" 10 "time" 11 ) 12 13 import "C" 14 15 var initCh = make(chan int, 1) 16 var ranMain bool 17 18 func init() { 19 // emulate an exceedingly slow package initialization function 20 time.Sleep(100 * time.Millisecond) 21 initCh <- 42 22 } 23 24 func main() { ranMain = true } 25 26 //export DidInitRun 27 func DidInitRun() bool { 28 select { 29 case x := <-initCh: 30 if x != 42 { 31 // Just in case initCh was not correctly made. 32 println("want init value of 42, got: ", x) 33 syscall.Exit(2) 34 } 35 return true 36 default: 37 return false 38 } 39 } 40 41 //export DidMainRun 42 func DidMainRun() bool { return ranMain }