-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: sync: add (*WaitGroup).WaitUnlock(l Locker) #36349
Comments
I think you are looking for condition variables. |
The passed in `releaseFunc` will be called immediately if no need to wait, or right before wait(`runtime_Semacquire`). This can be useful when some resources can be released before wait, e.g, when `Add/Wait` are synchronised by RWMutex, where `Add` only happens while holding `RLock` and `Wait` only happens while holding `Lock`. Here's a concrete example: https://github.com/zhiqiangxu/util/blob/master/closer/state.go#L58 Fixed golang#36349
The passed in `Locker` will be called immediately if no need to wait, or right before wait(`runtime_Semacquire`). This can be useful when some resources can be released before wait, e.g, when `Add/Wait` are synchronised by RWMutex, where `Add` only happens while holding `RLock` and `Wait` only happens while holding `Lock`. Here's a concrete example: https://github.com/zhiqiangxu/util/blob/master/closer/state.go#L58 Fixed golang#36349
@ianlancetaylor I've re-implemented it with But I think it's also useful for I've also changed |
I think it's problematic to add a user callback to lock heavy code like |
Yes, that's why I've changed Regarding callbacks, in fact |
In the linked example, why do you need the call to It looks like you're already ensuring that |
It seems like you could close a channel here instead of signaling a |
That line may be called multiple times under race conditions. |
Sure, but it would be trivial to use an exclusive lock (instead of a read-lock) and |
Some demo code? :) Anyway this proposal is just about code-reuse,not some lack of mechanics:) The link in the OP shows how code can be simplified with it |
In general the things in package sync are meant to stand alone. Synchronization code is subtle, and adding callbacks like this or mixing operations on one synchronization type with another lead to bugs. There are also ways to write the given code without the new API. Based on the discussion above, this seems like a likely decline. Leaving open for a week for final comments. |
No change in consensus, so declining. |
The passed in
Locker
will beUnlock
ed immediately if no need to wait, or right before wait(runtime_Semacquire
).This can be useful when some resources can be released before wait, e.g, when
Add/Wait
are synchronised byRWMutex
,where
Add
only happens while holdingRLock
andWait
only happens while holdingLock
.Here's a concrete example:
https://github.com/zhiqiangxu/util/blob/470c7893cce57bd749d95f66cd116e8880eaa068/closer/strict.go#L69
The text was updated successfully, but these errors were encountered: