lock-hierarchy 0.2.0

Prevent dead locks by enforcing lock hierarchies
Documentation
  • Coverage
  • 50%
    3 out of 6 items documented2 out of 2 items with examples
  • Size
  • Source code size: 26.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.78 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Aleph-Alpha/lock-hierarchy-rs
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pacman82

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