#mutex #deadlock #single-thread #no-alloc

no-std one-shot-mutex

One-shot locks that panic instead of (dead)locking on contention

2 releases

0.1.1 Apr 4, 2024
0.1.0 Apr 3, 2024

#172 in No standard library

Download history 217/week @ 2024-06-15 165/week @ 2024-06-22 335/week @ 2024-06-29 183/week @ 2024-07-06 264/week @ 2024-07-13 105/week @ 2024-07-20 168/week @ 2024-07-27 189/week @ 2024-08-03 274/week @ 2024-08-10 185/week @ 2024-08-17 259/week @ 2024-08-24 88/week @ 2024-08-31 74/week @ 2024-09-07 470/week @ 2024-09-14 41/week @ 2024-09-21 260/week @ 2024-09-28

849 downloads per month
Used in 2 crates (via hermit-sync)

MIT/Apache

17KB
356 lines

one-shot-mutex

Crates.io docs.rs CI

One-shot locks that panic instead of (dead)locking on contention.

These locks allow no contention and panic instead of blocking on lock if they are already locked. This is useful in situations where contention would be a bug, such as in single-threaded programs that would deadlock on contention.

use one_shot_mutex::OneShotMutex;

static X: OneShotMutex<i32> = OneShotMutex::new(42);

let x = X.lock();

// This panics instead of deadlocking.
// let x2 = X.lock();

// Once we unlock the mutex, we can lock it again.
drop(x);
let x = X.lock();

For API documentation, see the docs.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~160KB