-
Couldn't load subscription status.
- Fork 13.9k
Fix RwLock::try_write #25153
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
Fix RwLock::try_write #25153
Conversation
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
|
Nominating for beta by request of the author. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that a poisoned rwlock will also return an Err even if it was successful in the try_read, so technically the lock could be locked if Err is returned. Perhaps the docs could be updated slightly to account for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the pre-existing Failure section covers this, but it's outside the diff of this PR (https://github.com/jgallagher/rust/blob/rwlock-try-write/src/libstd/sync/rwlock.rs#L187-L190). Is what it states incorrect, or should this paragraph be reworded to include it somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm ok so upon re-reading my original though that this indicates Err means the lock wasn't grabbed isn't quite right, it just means that if it couldn't be grabbed Err is returned, so looks good to me!
|
Nice catch @jgallagher! Just one small nit from me on the doc updates and otherwise this is good to go. |
Previously, `try_write` actually only obtained shared read access (but would return a `RwLockWriteGuard` if that access was successful). Also updates the docs for `try_read` and `try_write`, which were leftover from when those methods returned `Option` instead of `Result`.
Previously,
try_writeactually only obtained shared read access (but would return aRwLockWriteGuardif that access was successful).Also updates the docs for
try_readandtry_write, which were leftover from when those methods returnedOptioninstead ofResult.