https://github.com/aleph-alpha/lock-hierarchy-rs
Validate lock hierarchies in Rust code
https://github.com/aleph-alpha/lock-hierarchy-rs
Last synced: 9 months ago
JSON representation
Validate lock hierarchies in Rust code
- Host: GitHub
- URL: https://github.com/aleph-alpha/lock-hierarchy-rs
- Owner: Aleph-Alpha
- License: mit
- Created: 2022-09-20T13:15:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-12T10:54:23.000Z (over 1 year ago)
- Last Synced: 2025-06-23T07:07:26.589Z (about 1 year ago)
- Language: Rust
- Size: 27.3 KB
- Stars: 3
- Watchers: 13
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Lock hierarchy
This Rust crate offers debug assertions for violations of lock hierarchies. No runtime overhead or protection occurs for release builds.
## Usage
```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();
```
```rust
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();
```