Go - sharing work - Goroutines and Channels - Concurrency
Head First Go、 Jay McGavren(著)、O’Reilly Media)の Chapter 13(sharing work - Goroutines and Channels)、p.369(Exercise)の解答を求めてみる。
コード
main.go
package main
import (
"fmt"
"time"
)
func repeat(s string) {
for i := 0; i < 25; i++ {
fmt.Print(s)
}
}
func main() {
go repeat("x")
go repeat("y")
time.Sleep(time.Second)
}
入出力結果(Terminal, Zsh)
% go run ./main.go
yyyyyyyyyyyyyyyyyyyyyyyyyxxxxxxxxxxxxxxxxxxxxxxxxx%