#lock #hierarchy #mutex #level #violation #thread #hierarchies

lock-hierarchy

Prevent dead locks by enforcing lock hierarchies

2 releases

0.1.2 Sep 20, 2022
0.1.1 Sep 20, 2022

#1081 in Concurrency

Download history 141/week @ 2024-07-28 135/week @ 2024-08-04 152/week @ 2024-08-11 110/week @ 2024-08-18 80/week @ 2024-08-25 71/week @ 2024-09-01 46/week @ 2024-09-08 57/week @ 2024-09-15 154/week @ 2024-09-22 164/week @ 2024-09-29 187/week @ 2024-10-06 117/week @ 2024-10-13 127/week @ 2024-10-20 64/week @ 2024-10-27 89/week @ 2024-11-03 150/week @ 2024-11-10

446 downloads per month

MIT license

8KB
129 lines

Lock hierarchy

This Rust crate offers debug assertions for violations of lock hierarchies. No runtime overhead or protection occurs for release builds.

Usage

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();

lib.rs:

This crate offers debug assertions for violations of lock hierarchies. No runtime overhead or protection occurs for release builds.

No runtime deps