| Crates.io | lock-hierarchy |
| lib.rs | lock-hierarchy |
| version | 0.2.0 |
| created_at | 2022-09-20 13:46:44.683692+00 |
| updated_at | 2025-02-12 10:54:17.750196+00 |
| description | Prevent dead locks by enforcing lock hierarchies |
| homepage | |
| repository | https://github.com/Aleph-Alpha/lock-hierarchy-rs |
| max_upload_size | |
| id | 669917 |
| size | 27,395 |
This Rust crate offers debug assertions for violations of lock hierarchies. No runtime overhead or protection occurs for release builds.
use lock_hierarchy::Mutex;
let mutex_a = Mutex::new(()); // Level 0
let mutex_b = Mutex::with_level((), 0); // also level 0
// Fine, first mutex in thread
let _guard_a = mutex_a.lock().unwrap();
// Must panic, lock hierarchy violation
let _guard_b = mutex_b.lock().unwrap();
use lock_hierarchy::Mutex;
let mutex_a = Mutex::with_level((), 1); // Level 1
let mutex_b = Mutex::new(()); // level 0
// Fine, first mutex in thread
let _guard_a = mutex_a.lock().unwrap();
// Fine: 0 is lower level than 1
let _guard_b = mutex_b.lock().unwrap();