github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/misc/cgo/testcshared/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() {
    25  	ranMain = true
    26  }
    27  
    28  //export DidInitRun
    29  func DidInitRun() bool {
    30  	select {
    31  	case x := <-initCh:
    32  		if x != 42 {
    33  			// Just in case initCh was not correctly made.
    34  			println("want init value of 42, got: ", x)
    35  			syscall.Exit(2)
    36  		}
    37  		return true
    38  	default:
    39  		return false
    40  	}
    41  }
    42  
    43  //export DidMainRun
    44  func DidMainRun() bool {
    45  	return ranMain
    46  }