package main
import (
"fmt"
"sync"
)
func main() {
hello := func(wg *sync.WaitGroup, id int) {
defer wg.Done()
fmt.Printf("hello from %v\n", id)
}
numGreeters := 5
var wg sync.WaitGroup
wg.Add(numGreeters)
for i := 0; i < numGreeters; i++ {
go hello(&wg, i+1)
}
wg.Wait()
}
image.png
网友评论