Lock ordering macro.
Raison D'Être
This crate provides a simple lock ordering procmacro for ensuring a deterministic locking order, which is useful as a pattern to prevent deadlocks between fine-grain mutex use.
It also serves to remove the unwrap()
of panic-propagation between threads in the case of
poisoned locks. This is my favoured approach for handling an already panicking program, but
makes it difficult to find other non-valid usages of unwrap()
in the code.
Basic Usage
- The
mut
is optional based on if you want mutability, but must be prior to the identifier - The identifier can be multiple field lookups, ie
self.locks.connections
and will result in a bound variableconnections
as the last part of the full identifier. - There can be one or more locks provided, separated by
,
, they will be ordered lexicographially by the bound variable name.
Thus an example like this:
use lock;
use Mutex;
let lock1 = new;
let lock2 = new;
let lock3 = new;
Would expand to:
use lock;
use Mutex;
let lock1 = new;
let lock2 = new;
let lock3 = new;
Future direction
- Support for RwLock
- Support for bare non-poisoning locks such as
parking_lot
, which don't requireunwrap()
.