Crate smr_swap

Crate smr_swap 

Source
Expand description

A minimal locking, version-based concurrent swap library.

This library provides a mechanism to swap values atomically while allowing concurrent readers to access the old value until they are done. It uses swmr-cell for version-based garbage collection.

§Example

use smr_swap::SmrSwap;
use std::thread;

let mut swap = SmrSwap::new(0);

// Get a thread-local reader
let local = swap.local();

// Writer stores a new value
swap.store(1);

// Read in another thread
let local2 = swap.local();
let handle = thread::spawn(move || {
    let guard = local2.load();
    assert_eq!(*guard, 1);
});

handle.join().unwrap();

Structs§

CellLocalReader
A reader thread’s local version state.
CellSwmrReader
A handle for creating LocalReaders that can be shared across threads.
LocalReader
Thread-local reader handle, not Sync.
PinGuard
A guard that keeps the current thread pinned to a version.
ReadGuard
RAII guard for reading values.
SmrReader
A handle for creating LocalReaders that can be shared across threads.
SmrSwap
Main entry point for the SMR swap library.