gobyexample/src/scatter-gather/scatter-gather.go
2012-10-07 09:08:19 -07:00

27 lines
498 B
Go

// ## Scatter-Gather
package main
import "sync"
import "time"
import "math/rand"
import "fmt"
func main() {
times := new([20]int)
wait := new(sync.WaitGroup)
for i := 0; i < 20; i++ {
n := i
wait.Add(1)
go func() {
opTime := time.Duration(rand.Intn(2000))
time.Sleep(opTime * time.Millisecond)
fmt.Println(n)
times[n] = opTime
wait.Done()
}()
}
wait.Wait()
fmt.Println(*times)
}