1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
func Practice3() { runtime.GOMAXPROCS(1) //use no more than one logic cpu wg := sync.WaitGroup{} wg.Add(20) for i := 0; i < 10; i++ { go func() { fmt.Println("i: ", i) wg.Done() }() if i == 9 { fmt.Println("loop1 over") } } for i := 10; i < 20; i++ { //fmt.Println(i) go func() { fmt.Println("i: ", i) wg.Done() }() if i == 19 { fmt.Println("loop2 over") } } wg.Wait() } |
以上程序的输出是什么?
知识点:
goroutines and loop
最新评论
loop1 over
loop2 over
赞