-
Notifications
You must be signed in to change notification settings - Fork 341
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
RwLock: support upgrades/downgrades #704
Comments
I'm not sure what such an API would look like in a handle-based language like Rust. Currently, libstd RwLock, which our RwLock is modelled after also doesn't support this. Also, upgrading from read to write requires that all other readers are dropped, too, so this an operation that needs to be waited for and also return another other handle. So I have a hard time figuring out a good API that is better then "acquire reader -> drop reader -> acquire writer -> drop writer -> acquire reader again`. |
This sequence is not atomic. As for the API, intuitively I'd go with: RwLock::write(&self) -> WriteGuard
RwLock::read(&self) -> ReadGuard
WriteGuard::downgrade(self) -> ReadGuard
ReadGuard::upgrade(self) -> WriteGuard
Sure, but why is that a problem? The implementation would wait until the requestor is the last reader (and block others from acquiring new read/write access) and could then be "upgraded" into a |
The folks over at |
@devashishdxt Gah, you are right, obviously it isn't atomic ;). Sorry, I wrote the reply far too late at night. Well, coming back to the original problem, async-std does reimplement std in a sync fashion, so an interface should be implemented in std first unless there's a very strong cause. The reason for this is mainly that we see libstd interfaces as well-vetted and well understood. |
I think you tagged me by mistake ;) |
@devashishdxt Gah! Also, don't use GH in the morning :). |
Let me bring the suggestion to Edit: rust-lang/rust#69240 |
I think it would be great (certainly useful for me) if
RwLock
were to support read-write upgrades and write-read downgrades. Currently I don't see a way to accomplish the same and I always have to get write access over the entire operation.The text was updated successfully, but these errors were encountered: