shared-lock

Crates.ioshared-lock
lib.rsshared-lock
version0.1.0
created_at2025-06-22 10:31:40.460959+00
updated_at2025-06-22 10:31:40.460959+00
descriptionA lock that protects multiple objects at once.
homepage
repositoryhttps://github.com/mahkoh/shared-lock
max_upload_size
id1721542
size56,884
(mahkoh)

documentation

README

shared-lock

crates.io docs.rs MSRV

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.

Safety

This crate has 100% test coverage generated through mutation testing and all tests are run through miri.

MSRV

The MSRV is max(1.85, stable - 3).

License

This project is licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.

Commit count: 0

cargo fmt