I am very new to golang and I was trying out goroutine, while it's quite easy to run things concurrently, I am a bit surprised the way golang to "join the threads" using WaitGroup
.
As far as I know, the goroutine needs to have reference to the WaitGroup object to call Done()
, which means, I have to either make the goroutine to accept a WaitGroup
object, or make WaitGroup
object global to the goroutine.
But in other languages like Python, you call thread.join()
, the "controlling" part sits outside of the thread code.
Like I said, I am very new to golang, I don't know why it was designed this way, could someone please shed some light on this aspect?
UPDATE: I hope the argument is not based on 'Goroutine vs Thread', at the end of the day they both try to achieve (some kind of) 'concurrency', my question is more about controlling the program flow.