Expand description
§SWMR Version-Based Single Object
This crate provides a single-writer, multi-reader (SWMR) cell that supports concurrent wait-free reads and lock-free writes using version-based garbage collection.
§Core Concepts
- Single Object: The
swmr_celllibrary manages a single versioned object perSwmrCell. - Version: The version counter represents the state of the object. Each write increments the version.
- Pinning: Readers pin the current version when they start reading, preventing the writer from reclaiming that version (and any older versions still visible to other readers) until they are done.
§Typical Usage
use swmr_cell::SwmrCell;
// 1. Create a new SWMR cell with an initial value
let mut cell = SwmrCell::new(42i32);
// 2. Create a local reader for this thread (or pass to another thread)
let local = cell.local();
// 3. Pin and read the value by dereferencing the guard
let guard = local.pin();
assert_eq!(*guard, 42);
drop(guard);
// 4. Writer updates the value
cell.store(100i32);
// 5. Read the new value
let guard = local.pin();
assert_eq!(*guard, 100);
drop(guard);
// 6. Manually collect garbage (optional, happens automatically too)
cell.collect();Structs§
- Local
Reader - A reader thread’s local version state.
- PinGuard
- A guard that keeps the current thread pinned to a version.
- Swmr
Cell - A single-writer, multi-reader cell with version-based garbage collection.
- Swmr
Cell Builder - A builder for configuring and creating a SWMR cell.
- Swmr
Reader - A handle for creating
LocalReaders that can be shared across threads.