no_deadlock not work with threads
Closed this issue · 1 comments
jackalchenxu commented
no_deadlocks seems wrongly judge about deadlock when deal with threads, here is the test code.
use std::time::Duration;
use std::sync::Arc;
// the test code run alright
// use std::sync::Mutex;
// no_deadlocks report deadlock error
use no_deadlocks::prelude::*;
fn main() {
let mut childs = vec![];
let m = Arc::new(Mutex::new(0));
for _ in 1..=10 {
let clone_m = m.clone();
childs.push(std::thread::spawn(move||{
let mut m = clone_m.lock().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
*m = 1;
}))
}
for c in childs.into_iter() {
c.join();
}
}
p-avital commented
Thanks for signaling it!
That was an issue where the thread's dependency on the mutex wasn't deleted from the dependency graph when the mutex was acquired, causing false positives on reentrance detection. Fixed on master and crates.io version 1.1.2 :)