#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

#115 in No standard library

Download history 143/week @ 2024-03-28 837/week @ 2024-04-04 459/week @ 2024-04-11 299/week @ 2024-04-18 158/week @ 2024-04-25 311/week @ 2024-05-02 253/week @ 2024-05-09 328/week @ 2024-05-16 101/week @ 2024-05-23 176/week @ 2024-05-30 148/week @ 2024-06-06

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


356 lines


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.
let x = X.lock();

For API documentation, see the docs.


Licensed under either of

at your option.


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.