aarc
Quickstart
Arc/Weak: drop-in replacements for the standard library'sArcandWeak, but implemented with deferred reclamation semantics.AtomicArc/AtomicWeak: variants ofArcandWeakwith atomically updatable pointers, supporting standard atomic operations likeloadandcompare_exchange.Guard: A novel smart pointer that can be loaded fromAtomicArcorAtomicWeak, designed to reduce contention when multiple threads operate on the same atomic variable. It prevents deallocation but does not contribute to reference counts. (This was renamed fromSnapshotin an earlier version, to reduce confusion.)
Motivation
Data structures built with Arc typically require locks for synchronization, as only
the reference counts may be atomically updated, not the pointer nor the contained data. While locks
are often the right approach, lock-free data structures can have better theoretical and practical
performance guarantees in highly-contended settings.
Instead of protecting in-place updates with locks, an alternative approach is to perform copy-on-write updates by
atomically installing pointers. To avoid use-afer-free, mechanisms for safe memory reclamation (SMR) are typically
utilized (i.e. hazard pointers, epoch-based reclamation). aarc uses the blazingly fast algorithm provided by the
fast-smr crate and builds on top of it, hiding unsafety and providing
convenient RAII semantics through reference-counted pointers.
Examples
Example 1: Treiber Stack
Roadmap
- relax atomic orderings from SeqCst to Acq/Rel
- add tagged pointers
- add more tests and stabilize APIs