Show cycle backtraces when they happen

This commit is contained in:
2023-08-27 18:06:11 +02:00
parent 6be3e05cab
commit 068303d81d
5 changed files with 96 additions and 33 deletions

26
examples/mutex_cycle.rs Normal file
View File

@@ -0,0 +1,26 @@
//! Show what a crash looks like
//!
//! This shows what a traceback of a cycle detection looks like. It is expected to crash.
use tracing_mutex::stdsync::Mutex;
fn main() {
let a = Mutex::new(());
let b = Mutex::new(());
let c = Mutex::new(());
// Create an edge from a to b
{
let _a = a.lock();
let _b = b.lock();
}
// Create an edge from b to c
{
let _b = b.lock();
let _c = c.lock();
}
// Now crash by trying to add an edge from c to a
let _c = c.lock();
let _a = a.lock(); // This line will crash
}