<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する,省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) } ϓϩηεͷઃఆ ฒྻॲཧ෦(ແ໊ؔ)