Expand description
A lock-free hazard pointer implementation for safe memory reclamation.
Hazard pointers allow threads to safely read shared pointers while other threads may concurrently remove and deallocate the pointed-to objects. A thread “protects” a pointer by publishing it in a hazard slot; reclamation of retired objects is deferred until no thread holds a matching hazard.
§Example
use std::sync::atomic::Ordering;
use lockout_hazard::{Domain, AtomicPtr};
static DOMAIN: Domain = Domain::new();
let shared = AtomicPtr::new(Box::into_raw(Box::new(42)));
// Protect the pointer so it won't be reclaimed while we read it.
let guard = DOMAIN.protect(&shared).unwrap();
assert_eq!(*guard, 42);
// Swap in a new value — returns a Replaced that must be retired.
let old = shared.swap(Box::into_raw(Box::new(100)), Ordering::SeqCst);
guard.clear();
old.retire(&DOMAIN);
// Clean up the remaining allocation.
shared.swap(std::ptr::null_mut(), Ordering::SeqCst).retire(&DOMAIN);
DOMAIN.collect();