genzero

Crates.iogenzero
lib.rsgenzero
version0.2.0
sourcesrc
created_at2024-06-18 23:50:26.174595
updated_at2024-08-09 00:44:42.938646
descriptiongenzero is a library that lets you get the latest value of a type.
homepagehttps://github.com/therishidesai/genzero
repositoryhttps://github.com/therishidesai/genzero
max_upload_size
id1276314
size36,882
Rishi Desai (therishidesai)

documentation

README

genzero

genzero is a library that lets you get the latest value of a type.

Why genzero?

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.

How to use genzero?

genzero's API is similar to a crossbeam::channel or a std:sync::mpsc

Simple Example

// Initialize first value to 0
let (mut tx, rx) = genzero::new<u32>(0);

tx.send(10);

assert_eq!(rx.recv(), Some(10));
Commit count: 4

cargo fmt