view paper/src/go.go @ 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
children
line wrap: on
line source

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
}