]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testplugin/testdata/issue25756/main.go
runtime: remove crash_cgo_test CgoRaceSignal timeout
[gostls13.git] / misc / cgo / testplugin / testdata / issue25756 / main.go
1 // Copyright 2018 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 // Run the game of life in C using Go for parallelization.
6
7 package main
8
9 import (
10         "flag"
11         "fmt"
12         "plugin"
13 )
14
15 const MAXDIM = 100
16
17 var dim = flag.Int("dim", 16, "board dimensions")
18 var gen = flag.Int("gen", 10, "generations")
19
20 func main() {
21         flag.Parse()
22
23         var a [MAXDIM * MAXDIM]int32
24         for i := 2; i < *dim; i += 8 {
25                 for j := 2; j < *dim-3; j += 8 {
26                         for y := 0; y < 3; y++ {
27                                 a[i**dim+j+y] = 1
28                         }
29                 }
30         }
31
32         p, err := plugin.Open("life.so")
33         if err != nil {
34                 panic(err)
35         }
36         f, err := p.Lookup("Run")
37         if err != nil {
38                 panic(err)
39         }
40         f.(func(int, int, int, []int32))(*gen, *dim, *dim, a[:])
41
42         for i := 0; i < *dim; i++ {
43                 for j := 0; j < *dim; j++ {
44                         if a[i**dim+j] == 0 {
45                                 fmt.Print(" ")
46                         } else {
47                                 fmt.Print("X")
48                         }
49                 }
50                 fmt.Print("\n")
51         }
52 }