https://github.com/xudong-huang/rcu_cell
rust rcu cell library
https://github.com/xudong-huang/rcu_cell
Last synced: 17 days ago
JSON representation
rust rcu cell library
- Host: GitHub
- URL: https://github.com/xudong-huang/rcu_cell
- Owner: Xudong-Huang
- License: lgpl-3.0
- Created: 2017-10-24T02:18:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-25T01:44:19.000Z (about 1 month ago)
- Last Synced: 2025-04-10T01:14:45.233Z (17 days ago)
- Language: Rust
- Size: 107 KB
- Stars: 25
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/Xudong-Huang/rcu_cell/actions?query=workflow%3ACI+branch%3Amaster)
[](https://crates.io/crates/rcu_cell)
[](https://docs.rs/rcu_cell)# RcuCell
A lockless rcu cell implementation that can be used safely in multithread context.
## Features
- Support multi-thread read and write operations.
- The read operation would not block other read operations.
- The read operation is always waitless.
- The read operation is something like Arc::clone.
- The write operation would not block other read operations.
- The write operation is lockless.
- The write operation is something like Atomic Swap.
- The RcuCell could contain no data
- Could be compiled with no_std## Usage
```rust
use rcu_cell::RcuCell;
use std::sync::Arc;let t = Arc::new(RcuCell::new(10));
let t1 = t.clone();
let t2 = t.clone();
let d1 = t1.take().unwrap();
assert_eq!(*d1, 10);
assert_eq!(t1.read(), None);
let d2 = t2.write(42);
assert!(d2.is_none());
let d3 = t2.read().unwrap();
assert_eq!(*d3, 42);
```