Crates.io | shared-lock |
lib.rs | shared-lock |
version | 0.1.0 |
created_at | 2025-06-22 10:31:40.460959+00 |
updated_at | 2025-06-22 10:31:40.460959+00 |
description | A lock that protects multiple objects at once. |
homepage | |
repository | https://github.com/mahkoh/shared-lock |
max_upload_size | |
id | 1721542 |
size | 56,884 |
The shared-lock crate provides a re-entrant lock that can be used to lock multiple disconnected objects such as in the following example:
struct Context {
lock: Lock,
data1: Locked<Cell<u32>>,
}
struct Child {
context: Arc<Context>,
data2: Locked<Cell<u32>>,
}
Both objects in this example implement Sync
because Locked<T>: Sync
if
T: Send
.
After the lock has been locked once in a thread, locking it again is about as
expensive as cloning an Rc
and accessing the locked fields is essentially
free.
This crate has 100% test coverage generated through mutation testing and all tests are run through miri.
The MSRV is max(1.85, stable - 3)
.
This project is licensed under either of
at your option.