Thanks to visit codestin.com
Credit goes to lib.rs

#mutex #locking

bolt

The package provides a hierarchical read-write lock

8 unstable releases (3 breaking)

Uses new Rust 2024

0.3.0 Sep 8, 2025
0.2.2 Aug 17, 2025
0.1.2 Aug 16, 2025
0.0.1 Aug 16, 2025

#649 in Concurrency

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

557 downloads per month

Apache-2.0 OR MIT

15KB
239 lines

Bolt Package Documentation Build

The package provides a hierarchical read-write lock.

Given a hierarchical path defined as a sequence of progressively nested segments separated by slashes—as in a/b/c where c is nested in b and a, and b is nested in a—the locking mechanism ensures that

  • a writer is given access to the path only when the rightmost segment is not currently being read from or written into and is not nested in any segment that is currently being written into, and that

  • a reader is given access to the path only when the rightmost segment is not currently being written into and is not nested in any segment that is currently being written into.

For instance, one can concurrently write into a/b/c and a/b/d and read from a and a/b. However, reading from or writing into a/b/c or a/b/d would have to wait for a/b if the rightmost was acquired for writing, but one would be able to read from a.

Usage

const N: usize = 10;

let lock = std::sync::Arc::new(bolt::Lock::<N>::default());

{
    let lock = lock.clone();
    tokio::task::spawn(async move {
        let _guards = lock.write_backward("a/b/c").await;
    });
}

{
    let lock = lock.clone();
    tokio::task::spawn(async move {
        let _guards = lock.write_backward("a/b/d").await;
    });
}

Contribution

Your contribution is highly appreciated. Do not hesitate to open an issue or a pull request. Note that any contribution submitted for inclusion in the project will be licensed according to the terms given in LICENSE.md.

Dependencies

~3MB
~40K SLoC