wg能不能多线程Wait
package main
import (
"fmt"
"sync"
)
func main() {
wg := sync.WaitGroup{}
wg.Add(1)
for i := 0; i < 3; i++ {
go func(i int) {
wg.Wait()
fmt.Printf("%d done\n", i)
}(i)
}
wg.Done()
fmt.Println("main done")
}
package main
import (
"fmt"
"sync"
)
func main() {
wg := sync.WaitGroup{}
wg.Add(1)
for i := 0; i < 3; i++ {
go func(i int) {
wg.Wait()
fmt.Printf("%d done\n", i)
}(i)
}
wg.Done()
fmt.Println("main done")
}