Crates.io | axka-rcu |
lib.rs | axka-rcu |
version | 1.0.0 |
source | src |
created_at | 2024-07-31 23:19:33.640328 |
updated_at | 2024-07-31 23:19:33.640328 |
description | A reference-counted read-copy-update (RCU) primitive used for protecting shared data |
homepage | https://git.axka.fi/axka-rcu.git/about/ |
repository | https://github.com/axelkar/axka-rcu |
max_upload_size | |
id | 1321394 |
size | 32,018 |
A reference-counted read-copy-update (RCU) primitive useful for protecting shared data
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.
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:
Setup git send-email
:
Commit your changes, this will open up a text editor
git commit
Send your patches to me. The command sends the last commit
git send-email --to="axel@axka.fi" HEAD^
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.