Module parking_lot::deadlock
source · 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§
- acquire_
resource 🔒 ⚠Acquire a resource identified by key in the deadlock detector Noop ifdeadlock_detection
feature isn’t enabled. - release_
resource 🔒 ⚠Release a resource identified by key in the deadlock detector. Noop ifdeadlock_detection
feature isn’t enabled.