Hi, how do you share waitgroups between goroutines? From the video i see that you do not use pointers for wg. Doesn't that mean that each goroutine will get a new copy of a wait group?
The waitgroups are not pointers because they are declared locally to where they are used; notice the goroutine uses an anonymous function, so everything inside that block is still pointing to the same memory address. If the declaration of "func(val int64)" was outside of "main()", then that function would have to be changed to "func(val int64, c *Choreographer, wgSubs *sync.WaitGroup, wg *sync.WaitGroup)" . You can confirm this by printing their memory address using "fmt.Printf("%p", &wgXYZ")", you will see they are the same.
This content is exactly what I've been looking for, thank you!
Aidan, I'm glad you found it useful. Cheers
Thanks for sharing!
Ty for posting all this, learned lots
Thanks Tristan, I'm glad it worked for you. Take care.
Hi, how do you share waitgroups between goroutines? From the video i see that you do not use pointers for wg. Doesn't that mean that each goroutine will get a new copy of a wait group?
The waitgroups are not pointers because they are declared locally to where they are used; notice the goroutine uses an anonymous function, so everything inside that block is still pointing to the same memory address. If the declaration of "func(val int64)" was outside of "main()", then that function would have to be changed to "func(val int64, c *Choreographer, wgSubs *sync.WaitGroup, wg *sync.WaitGroup)" .
You can confirm this by printing their memory address using "fmt.Printf("%p", &wgXYZ")", you will see they are the same.
not sure about two wait groups :)
that feels heavy
Yes, I totally agree with you. Like I said in the video, I don't recommend any of this for production :)