Zentopia
9/1/2017 - 3:47 AM

WaitGroup使用示例

WaitGroup使用示例


import (
	"sync"
)

var wg *sync.WaitGroup

func action(arg int)  {
	println("the arg is:", arg)
	println("Hello")
	wg.Done()
}

func main()  {

	wg = new(sync.WaitGroup)
	for i := range []int{0, 1, 2, 3} {
		wg.Add(1)
		go action(i)
	}
	wg.Wait()
}