Module deadlock
Expand description
[Experimental] Deadlock detection
This feature is optional and can be enabled via the deadlock_detection
feature flag.
§Example
#[cfg(feature = "deadlock_detection")]
{ // only for #[cfg]
use std::thread;
use std::time::Duration;
use parking_lot::deadlock;
// Create a background thread which checks for deadlocks every 10s
thread::spawn(move || {
loop {
thread::sleep(Duration::from_secs(10));
let deadlocks = deadlock::check_deadlock();
if deadlocks.is_empty() {
continue;
}
println!("{} deadlocks detected", deadlocks.len());
for (i, threads) in deadlocks.iter().enumerate() {
println!("Deadlock #{}", i);
for t in threads {
println!("Thread Id {:#?}", t.thread_id());
println!("{:#?}", t.backtrace());
}
}
}
});
} // only for #[cfg]
Functions§
- Returns all deadlocks detected since the last call. Each cycle consist of a vector of
DeadlockedThread
.