-
Notifications
You must be signed in to change notification settings - Fork 343
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
Our macOS os_unfair_lock do not complain when they are moved while being locked #3859
Comments
Behavior changed a bit with #3966: the queue no longer moves with the lock. However, we should probably do something to detect a lock that is moved while being locked -- that seems like a rather dubious thing to do. The best way to do this probably is to store something non-zero in the lock whenever it is held, and to refuse initializing a new lock in |
Hm no that won't work -- one can leak the @joboet what is actually the behavior of that? Miri might be doing this wrong right now... calling use std::sync::Mutex;
use std::mem;
fn main() {
let m = Mutex::new(0);
mem::forget(m.lock());
// Move the lock while it is "held" (really: leaked)
let m2 = m;
// Now try to acquire the lock again.
let _guard = m2.lock();
} |
ensure that a macOS os_unfair_lock that is moved while being held is not implicitly unlocked Fixes rust-lang/miri#3859 We mark an os_unfair_lock that is moved while being held as "poisoned", which means it is not considered forever locked. That's not quite what the real implementation does, but allowing arbitrary moves-while-locked would likely expose a ton of implementation details, so hopefully this is good enough.
In #3745, the question came up what to do when a os_unfair_lock is moved. Apparently the real implementation uses the address of the lock to identify the wait queue, so a moved lock will be a "fork" of the old lock: it will start in whatever state the lock had at the time of the move, but reset the wait queue.
In Miri, we use a mutex ID tracked in the os_unfair_lock value to identify the lock, so the wait queue moves with the lock.I don't think it makes sense to exactly replicate the macOS behavior here, but it would make sense to detect when a lock is moved, and throw an "unsupported" error.
This could work similar to what #3784 does for pthread mutexes.The text was updated successfully, but these errors were encountered: