-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add value accessor methods to Mutex
and RwLock
#133406
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
Conversation
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
5d2f4af
to
2c98df2
Compare
2c98df2
to
b6446a1
Compare
@rustbot ready |
/// assert_eq!(mutex.get_cloned().unwrap(), 11); | ||
/// ``` | ||
#[unstable(feature = "lock_value_accessors", issue = "133407")] | ||
pub fn set(&self, value: T) -> Result<(), PoisonError<T>> { |
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.
Just to avoid the discussion getting lost - as I mentioned in rust-lang/libs-team#497, the type PoisonError<T>
assumes the T
is the result if you simply disregard poisoning. In this PR these are used to store the original input instead.
I suggest we either reword the documentation of PoisonError
Consumes this error indicating that a lock is poisoned, returning the
underlying guard to allow access regardless.
or create a different error type that is not associated with LockResult
.
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 have updated the documentation.
f0d47da
to
85fd82b
Compare
85fd82b
to
242c6c3
Compare
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.
The docs changes to the lock result are fine, moving the writing about the guard being contained to the methods explicitly probably makes it more clear even without the new use of the result.
@bors r+ |
get
,set
andreplace
methods toMutex
andRwLock
libs-team#485.lock_value_accessors
#133407.This PR adds
get
,set
andreplace
methods to theMutex
andRwLock
types for quick access to their contained values.One possible optimization would be to check for poisoning first and return an error immediately, without attempting to acquire the lock. I didn’t implement this because I consider poisoning to be relatively rare, adding this extra check could slow down common use cases.