go等待所有线程退出

code

package main

import (
    "fmt"
    "sync"
)

func main() {
    var wg sync.WaitGroup

    for i := 0; i < 10; i++ {
        wg.Add(1)
        go func(){
            fmt.Println("Hello World")
            wg.Done()
        }()
    }

    wg.Wait()
}

猜你喜欢

转载自blog.csdn.net/x356982611/article/details/80384471