sync wait group

This commit is contained in:
Jian Han 2018-01-04 21:02:20 +10:00
parent b30bfe7e11
commit 08f341f9af

View File

@ -1,11 +1,15 @@
package main
import "fmt"
import (
"fmt"
"sync"
)
func main() {
// unbuf()
// buf()
nBuf()
// nBuf()
syncWaitGroup()
}
/*
@ -45,3 +49,17 @@ func nBuf() {
<-done
}
}
func syncWaitGroup() {
var wg sync.WaitGroup
// 开N个后台打印线程
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
fmt.Println("你好, 世界", i)
wg.Done()
}(i)
}
// 等待N个后台线程完成
wg.Wait()
}