axka-rcu

Crates.ioaxka-rcu
lib.rsaxka-rcu
version1.0.0
sourcesrc
created_at2024-07-31 23:19:33.640328
updated_at2024-07-31 23:19:33.640328
descriptionA reference-counted read-copy-update (RCU) primitive used for protecting shared data
homepagehttps://git.axka.fi/axka-rcu.git/about/
repositoryhttps://github.com/axelkar/axka-rcu
max_upload_size
id1321394
size32,018
Axel Karjalainen (axelkar)

documentation

README

axka-rcu

Crates.io Documentation

A reference-counted read-copy-update (RCU) primitive useful for protecting shared data

Example

use std::{thread::sleep, time::Duration, sync::Arc};
use axka_rcu::Rcu;

#[derive(Clone, Debug, PartialEq)]
struct Player {
    name: &'static str,
    points: usize
}

let players = Arc::new(Rcu::new(Arc::new(vec![
    Player { name: "foo", points: 100 }
])));
let players2 = players.clone();

// Lock-free writing
std::thread::spawn(move || players2.update(|players| {
    sleep(Duration::from_millis(50));
    players.push(Player {
        name: "bar",
        points: players[0].points + 50
    })
}));

// Lock-free reading
assert_eq!(*players.read(), [
    Player { name: "foo", points: 100 }
]);

sleep(Duration::from_millis(60));
assert_eq!(*players.read(), [
    Player { name: "foo", points: 100 },
    Player { name: "bar", points: 150 }
]);

Check out the documentation for more details.

Contributing patches

Please first make sure that you have not introduced any regressions and format the code by running the following commands at the repository root.

cargo fmt
cargo clippy
cargo test

You can either make a GitHub pull request or email me directly:

  1. Setup git send-email:

    https://git-send-email.io/

  2. Commit your changes, this will open up a text editor

    git commit

  3. Send your patches to me. The command sends the last commit

    git send-email --to="axel@axka.fi" HEAD^

License

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.

Commit count: 0

cargo fmt