2016-05-24   go 

go練習

コード

package main

import "fmt"
import "time"

func f(name string) {
  for true {
    fmt.Print(name)
  }
}

func main() {
  go f("A")
  go f("B")
  go f("C")
  time.Sleep(3 * time.Second)
}

結果

$ go run a.go
ABABABABABABABABABAB(略)ABCABCABCABCABCABCBACBACABCABCABCABCABCABCACAC

参考

http://www.slideshare.net/takuyaueda967/goroutine-channel-go

 2016-05-24   go