changeset 45:d24a4c224f71

Add go examples
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 05 Feb 2018 22:36:56 +0900
parents ca7c9340f60b
children b39f72af2e43
files paper/master_paper.pdf paper/src/go.go
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file paper/master_paper.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/go.go	Mon Feb 05 22:36:56 2018 +0900
@@ -0,0 +1,19 @@
+func main() {
+    c := make(chan []int)
+    for i :=0; i < *split; i++ {
+        // call goroutine
+        go twice(list, prefix, i, c);
+    }
+
+    for i :=0; i < *split; i++ {
+        // join twice routins
+        <- c
+    }
+}
+
+func twice(list []int, prefix int, index int, c chan []int) {
+    for i := 0; i < prefix; i++ {
+        list[prefix*index+i] = list[prefix*index+i] * 2;
+    }
+    c <- list
+}