#lock-free #rcu #atomic #data-structures #data-access

nightly no-std rcu_128

RCU (Read-Copy-Update) implementation for platforms supporting atomic 128-bit operations

11 releases

0.2.2 Jun 25, 2024
0.2.1 Jun 21, 2024
0.1.9 Jun 21, 2024

#590 in Concurrency

Download history 40/week @ 2024-07-23 19/week @ 2024-07-30 15/week @ 2024-09-10 6/week @ 2024-09-17 28/week @ 2024-09-24 1/week @ 2024-10-01

546 downloads per month

MIT license

12KB
135 lines

Rcu128

Rcu128 is a Rust library that provides a concurrent data structure for read-copy-update (RCU) style access to a value. It allows multiple readers to access the value concurrently while ensuring safe updates by blocking the release of the value until all current readers have finished reading the old value.

Limitation

Only available on platforms that support atomic loads and stores of u128.

Usage

Add to your Cargo.toml

[dependencies]
rcu_128 = { git = "https://github.com/cyborg42/rcu_128.git" }

Example

use rcu_128::RcuCell;

fn main() {
    let rcu_cell = RcuCell::new(42);

    // Read the value
    {
        let guard = rcu_cell.read();
        assert_eq!(*guard, 42);
    }

    // Write a new value
    rcu_cell.write(100);

    // Upate with a function
    rcu_cell.update(|value| value + 1);

    // Read the updated value
    {
        let guard = rcu_cell.read();
        assert_eq!(*guard, 101);
    }
}

License

This project is licensed under the MIT License. See the LICENCE file for details.

Dependencies

~0.4–5MB
~11K SLoC