Crates.io | genzero |
lib.rs | genzero |
version | 0.2.0 |
source | src |
created_at | 2024-06-18 23:50:26.174595 |
updated_at | 2024-08-09 00:44:42.938646 |
description | genzero is a library that lets you get the latest value of a type. |
homepage | https://github.com/therishidesai/genzero |
repository | https://github.com/therishidesai/genzero |
max_upload_size | |
id | 1276314 |
size | 36,882 |
genzero is a library that lets you get the latest value of a type.
There are many concurrency programs where one may have many reader threads that want to get the latest value of a type that is being updated by another thread (spmc). A naive approach would be using a Mutex/RWLock on the shared piece of data. Locks are unfortunately slow in many cases and specifically don't allow us to maximize throughput. RCU is a technique initially developed in the linux kernel that allows the pattern described above while not blocking the writers and increasing throughput (Fedor Pikus CppCon 2017 Talk on RCU). crossbeam-epoch is an epoch based memory reclaimer that implements an RCU method for Rust. genzero is an API to achieve this simple spmc latest value pattern built on top of the crossbeam-epoch library.
genzero's API is similar to a crossbeam::channel
or a std:sync::mpsc
// Initialize first value to 0
let (mut tx, rx) = genzero::new<u32>(0);
tx.send(10);
assert_eq!(rx.recv(), Some(10));