package main import ( "fmt" "sync" "time" ) func main(){ var wg sync.WaitGroup testFunc:=func(wg *sync.WaitGroup,id int){ defer wg.Done() fmt.Printf("%v",id) time.Sleep(2) } N:=3 wg.Add(N) for i:=0;i<3;i++{ //defer wg.Do/ne() go testFunc(&wg,i) } //wg.Done() //fmt.Println("11111111") wg.Wait() //fmt.Println("22222222") }
07-24
1175
06-22
260
11-06
1037
11-07
443
11-05
780