-
Notifications
You must be signed in to change notification settings - Fork 50
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
Data race in Arc::into_unique
#106
Comments
Ah, even “simpler”, just: use triomphe::Arc;
fn main() {
let a = Arc::new(());
let _a = a.clone();
std::thread::spawn(move || {
Arc::into_unique(a);
});
} is enough for miri to catch a race. |
How are you running this, and on what nightly version? I can't seem to get either the full or simplified reproductions to trigger an error with Miri. 🤔 I tried both as standalone test files ( |
rustc +nightly --version
cargo new repro
cd repro
mkdir triomphe
cd triomphe
git init
git remote add origin https://github.com/Manishearth/triomphe.git
git fetch --depth 1 origin fae2334e83302948b17a7b449858931db0de1ac3
git checkout fae2334e83302948b17a7b449858931db0de1ac3
cd ..
cargo add --path ./triomphe
cat >./src/main.rs <<EOL
use triomphe::Arc;
fn main() {
let a = Arc::new(0);
let b = a.clone();
std::thread::spawn(move || {
let _value = *b;
});
std::thread::spawn(move || {
*Arc::into_unique(a).unwrap() += 1;
});
}
EOL
cargo +nightly miri run |
These probably do rely on arbitrary execution order, which might be miri version dependent, or dependent on other factors. If you try this, try both permutations between std::thread::spawn(move || {
let _value = *b;
});
std::thread::spawn(move || {
*Arc::into_unique(a).unwrap() += 1;
}); and std::thread::spawn(move || {
*Arc::into_unique(a).unwrap() += 1;
});
std::thread::spawn(move || {
let _value = *b;
}); Edit: Or a sleep, to make the use triomphe::Arc;
fn main() {
let a = Arc::new(0);
let b = a.clone();
let t1 = std::thread::spawn(move || {
let _value = *b;
});
let t2 = std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_secs(1));
if let Some(mut u) = Arc::into_unique(a) {
*u += 1
}
});
t1.join().unwrap();
t2.join().unwrap();
} |
Yeah, weird... maybe it's something about the generated code for running it as a test. I was able to get it to reproduce with your full MVCE; thanks for that. 👍🏻 |
see also my comments in #103
The text was updated successfully, but these errors were encountered: