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

lock-hierarchy

通过强制执行锁层次结构来防止死锁

2 个版本

0.1.2 2022 年 9 月 20 日
0.1.1 2022 年 9 月 20 日

#1027并发

Download history 233/week @ 2024-03-14 67/week @ 2024-03-21 141/week @ 2024-03-28 103/week @ 2024-04-04 276/week @ 2024-04-11 213/week @ 2024-04-18 299/week @ 2024-04-25 560/week @ 2024-05-02 162/week @ 2024-05-09 254/week @ 2024-05-16 293/week @ 2024-05-23 251/week @ 2024-05-30 348/week @ 2024-06-06 262/week @ 2024-06-13 251/week @ 2024-06-20 200/week @ 2024-06-27

1,109 每月下载量

MIT 许可证

8KB
129

锁层次结构

这个 Rust 包提供了对锁层次结构违规的调试断言。发布构建不会产生运行时开销或保护。

用法

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:

此包提供对锁层次结构违规的调试断言。发布构建不会产生运行时开销或保护。

无运行时依赖