Example for sync.WaitGroup correct?
Yes, this example is correct. It is important that the wg.Add() happens before the go statement to prevent race conditions. The following would also be correct: func main() { var wg sync.WaitGroup wg.Add(1) go dosomething(200, &wg) wg.Add(1) go dosomething(400, &wg) wg.Add(1) go dosomething(150, &wg) wg.Add(1) go dosomething(600, &wg) wg.Wait() fmt.Println(“Done”) } However, it is rather … Read more