Summary
PulseMap's MetaWord uses AtomicU64 with compare_exchange_weak in a CAS loop (on_access method) to update eviction priorities lock-free. The AccessBuffer also uses multiple atomics (AtomicU32, AtomicUsize) for its lock-free ring buffer. While these appear correct by inspection, concurrent atomics are notoriously difficult to reason about. loom can systematically explore all possible thread interleavings to formally verify correctness.
What To Do
1. Add loom as a dev-dependency
[dev-dependencies]
loom = "0.7"
2. Create tests/loom_meta.rs
Test the MetaWord::on_access CAS loop under concurrent access:
- Spawn 2-3 loom threads that simultaneously call
on_access() on different slots of the same MetaWord
- After all threads complete, verify:
- All slot states are still valid (no corrupted bits)
- Frequency counters reflect the total number of accesses (no lost updates)
- Recency values are within valid range (0-7)
3. Create tests/loom_access_buffer.rs
Test the AccessBuffer push/drain under concurrent access:
- Spawn 2 producer threads calling
push() and 1 consumer calling drain()
- Verify no events are duplicated (each event drained at most once)
- Verify the lossy property: dropped events are acceptable, corrupted events are not
Key Considerations
loom replaces std::sync::atomic with its own instrumented version. You may need to add #[cfg(loom)] conditional compilation to swap atomic imports in meta.rs and access_buffer.rs.
- Keep the state space small: use 2-3 threads and minimal iterations. Loom explores ALL interleavings, so large state spaces will take too long.
- Reference: loom documentation
Acceptance Criteria
Summary
PulseMap's
MetaWordusesAtomicU64withcompare_exchange_weakin a CAS loop (on_accessmethod) to update eviction priorities lock-free. TheAccessBufferalso uses multiple atomics (AtomicU32,AtomicUsize) for its lock-free ring buffer. While these appear correct by inspection, concurrent atomics are notoriously difficult to reason about.loomcan systematically explore all possible thread interleavings to formally verify correctness.What To Do
1. Add loom as a dev-dependency
2. Create
tests/loom_meta.rsTest the
MetaWord::on_accessCAS loop under concurrent access:on_access()on different slots of the sameMetaWord3. Create
tests/loom_access_buffer.rsTest the
AccessBufferpush/drain under concurrent access:push()and 1 consumer callingdrain()Key Considerations
loomreplacesstd::sync::atomicwith its own instrumented version. You may need to add#[cfg(loom)]conditional compilation to swap atomic imports inmeta.rsandaccess_buffer.rs.Acceptance Criteria
cargo test --test loom_metapasses (loom explores all interleavings without panic)cargo test --test loom_access_bufferpasses#[cfg(loom)]import swaps if needed