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§
- Cell
Local Reader - A reader thread’s local version state.
- Cell
Swmr Reader - A handle for creating
LocalReaders that can be shared across threads. - Local
Reader - Thread-local reader handle, not Sync.
- PinGuard
- A guard that keeps the current thread pinned to a version.
- Read
Guard - 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.