1 stable release
1.0.0 | Jul 31, 2024 |
---|
#468 in Concurrency
20KB
285 lines
axka-rcu
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:
-
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^
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.
Dependencies
~170–340KB