What is the method set of `sync.WaitGroup`?

前端 未结 3 1338
[愿得一人]
[愿得一人] 2020-12-11 11:31

I have this simple program below

package main

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

var wg sync.WaitGroup

func main() {
    wg.Add(1)

    go f         


        
3条回答
  •  不知归路
    2020-12-11 12:19

    In your case you are modifying a global wg object, if you pass it to a function you have to use pointer because you need to modify the object itself. If you pass by value, inside your function you will be modifying a copy of it, not the object itself.

提交回复
热议问题