-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implementation of sync_nonpoison
and nonpoison_mutex
#134663
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
/// # Examples | ||
/// | ||
/// ``` | ||
/// use std::sync::Mutex; |
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.
These doctests need to be updated, they are using the poisioning mutex
use crate::ptr::NonNull; | ||
use crate::sys::sync as sys; | ||
|
||
/// A mutual exclusion primitive useful for protecting shared data |
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 for this one could probably just have a single example and then suggest looking at std::sync::poison::Mutex
for more, so that we don't have the detailed documentation repeated in multiple locations. Also make sure the doctests are using the right type here.
@Amanieu you may want to double check this |
This comment was marked as resolved.
This comment was marked as resolved.
Looks like you messed up a rebase. No worries, mistakes like this happen sadly (thanks Git for being so hard to use!). To get rid of all these commits, do a |
This comment has been minimized.
This comment has been minimized.
b0a1973
to
f023e42
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
This seems fine as a first step. Longer term we may want to consider changing the poisoning mutexes to be a wrapper around a non-poisoning |
|
||
#[unstable(feature = "nonpoison_mutex", issue = "134645")] | ||
impl<T: ?Sized> !Send for MutexGuard<'_, T> {} | ||
#[stable(feature = "mutexguard", since = "1.19.0")] |
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.
This should be unstable
under nonpoison_mutex
as well
/// | ||
/// rx.recv().unwrap(); | ||
/// ``` | ||
/// |
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.
Could you add an example to show the nonpoisoning behavior? Possibly:
use std::thread;
use std::sync::{Arc, nonpoison::Mutex};
let mutex = Arc::new(Mutex::new(0u32));
let mut handles = Vec::new();
for n in 0..10 {
let m = Arc::clone(&mutex);
let handle = thread::spawn(move || {
let mut guard = m.lock();
*guard += 1;
panic!("panic from thread {n} {guard}")
});
handles.push(handle);
}
for h in handles {
h.join();
}
println!("Finished, locked {} times", mutex.lock());
It would be good to have something similar in tests.rs
.
/// The exact behavior on locking a mutex in the thread which already holds | ||
/// the lock is left unspecified. However, this function will not return on | ||
/// the second call (it might panic or deadlock, for example). | ||
/// |
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.
Could you add something like "If this thread panics while the lock is held, the lock will be released like normal."
#[stable(feature = "std_debug", since = "1.16.0")] | ||
impl<T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'_, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Debug::fmt(&**self, f) | ||
} | ||
} | ||
|
||
#[stable(feature = "std_guard_impls", since = "1.20.0")] | ||
impl<T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'_, 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.
These should be unstable
For the errors like
You will need to run r? tgross35 @rustbot author |
Implementation of
sync_nonpoison
andnonpoison_mutex
Docs come straight from the poisoned Mutex, so they need to be updated.
Tracked by:
sync_nonpoison
andnonpoison_{condvar,mutex,once,rwlock}
#134645