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

lock-hierarchy

Prevent dead locks by enforcing lock hierarchies

2 releases

0.1.2 Sep 20, 2022
0.1.1 Sep 20, 2022

#1011 in Concurrency

Download history 328/week @ 2023-12-11 246/week @ 2023-12-18 41/week @ 2023-12-25 131/week @ 2024-01-01 192/week @ 2024-01-08 284/week @ 2024-01-15 335/week @ 2024-01-22 274/week @ 2024-01-29 213/week @ 2024-02-05 580/week @ 2024-02-12 526/week @ 2024-02-19 285/week @ 2024-02-26 272/week @ 2024-03-04 194/week @ 2024-03-11 162/week @ 2024-03-18 110/week @ 2024-03-25

749 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