The documentation explicitly states that it shouldn't be done if the WaitGroup counter is zero. Though I have occasionally written a code which does it, and it worked for several years, but weirdly, seems like the parallel execution of the critical section happens sometimes.
The goroutine has a Wait -> Add(1) -> Done chain. That time I expected it won't be started twice simultaneously (it actually seems to be sometimes anyway), and if it does, the first call would stay between Add and Done, and thus the second call and any other calls would block on Wait until the first one reaches Done. How does it work actually then, did the behaviour change between minor Go releases, and how should I have redone it properly if this behaviour is discouraged? Actually, I don't even remember why I didn't just use Mutex here, probably because I wanted to protect the whole critical section between Wait and Done, but only when the code between Add and Done is executed (executing the section between Wait and Add in parallel is fine and probably even needed sometimes). -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a499b92e-2db6-4b02-adf6-e7e69383f28cn%40googlegroups.com.