-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync: clarify WaitGroup.Done() behaviour when the counter is zero #39679
Comments
What do you think, @bcmills? |
A panic in Go is a recoverable operation, but a surplus call to On the other hand, we have already made that mistake for the |
Could there be any data race on the Developers with Java background where extra |
@leventov, if the counter goes negative, an overflow occurs in the That is not formally a data race, but it's also not a recoverable condition. You really don't want to call |
Recently, not being aware that Done panics if counter goes negative I wrote the following code (basically I wanted to ublock main as soon as any of the goroutines exit) If the docs were clearer on Done behavior, this would not have happened |
Done is a shortcut of Add(-1). The behavior is explained in Add docs. Maybe the docs of Done should mention this fact (it is a shortcut of Add(-1)). |
@go101 Yes, if this was mentioned in the docs, sure. But otherwise it's an implementation detail that I have to browse the code to learn. (and don't know if I can rely on this from release to release) |
I think it's worth noting that
WaitGroup.Done()
panics if the counter is already zero. It's currently inferrable from the docs, but not super obvious.The text was updated successfully, but these errors were encountered: