go sync.WaitGroup


import (
"fmt"
"sync"
"time"
)

var a int64 = 0
var b int64 = 0

func main() {
wg:=sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
a=1
b=2

}()

wg.Wait()

go func() {
fmt.Println(a,b)
}()
time.Sleep(time.Millisecond)

}

//
1 2
posted @ 2022-02-24 12:04  技术颜良  阅读(20)  评论(0编辑  收藏  举报