with_lock
Deadlock freedom
Using with_lock? Share it in the discussion!
This crate provides a simple way of managing Mutex's, and freeing your code from deadlocks. It is powered by parking_lot.
Example
Say you have this code:
use Mutex;
That code will run the first assert_eq!
fine, but the second wouldn't assert due to a deadlock.
However, we can prevent this by replacing our manual calls of .lock
with .with_lock
. Code that wouldn't error would look something like:
use WithLock;
This test would pass, and both assertions would be fulfilled. This is an example of how a dead lock was prevented.
Cell like API
with_lock
provides a custom Cell
like API powered by a Mutex.
use MutexCell;
For more examples, see the examples directory.
They can be run by cloning this repository and running cargo run --example <example_name>
.