1
2
3
4
5 package cgolife
6
7
8 import "C"
9
10 import "unsafe"
11
12 func Run(gen, x, y int, a []int32) {
13 n := make([]int32, x*y)
14 for i := 0; i < gen; i++ {
15 C.Step(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&a[0])), (*C.int)(unsafe.Pointer(&n[0])))
16 copy(a, n)
17 }
18 }
19
20
21 var chans [4]chan bool
22
23
24
25
26 func GoStart(i, xdim, ydim, xstart, xend, ystart, yend C.int, a *C.int, n *C.int) (int, int) {
27 c := make(chan bool, int(C.MYCONST))
28 go func() {
29 C.DoStep(xdim, ydim, xstart, xend, ystart, yend, a, n)
30 c <- true
31 }()
32 chans[i] = c
33 return int(i), int(i + 100)
34 }
35
36
37 func GoWait(i C.int) {
38 <-chans[i]
39 chans[i] = nil
40 }
41
View as plain text