Expand description
SharedCell<T> - cross-process single-value cell using the
SeqLock protocol over a memory-mapped file.
T: Copy plus a stable #[repr(C)] layout is the contract;
readers in different processes will memcpy the same bytes and
interpret them identically. The SeqLock retry loop guarantees
that a reader never observes a torn write across the writer’s
payload-update window.
§SeqLock protocol
Layout (one cache line):
+---------+---------+---------+--------------------------+
| magic | size | version | payload [u8; PAYLOAD] |
+---------+---------+---------+--------------------------+
u32 u32 u32 up to 52 bytesWriter protocol:
- Bump
versionfrom V (even) to V+1 (odd). All concurrent readers now see an odd version and will retry. - Memcpy the new payload bytes into place.
- Bump
versionfrom V+1 to V+2 (even). Readers resume.
Reader protocol:
- Load
version(Acquire). If odd, spin and retry. - Memcpy the payload into a local buffer.
- Load
versionagain (Acquire). If it changed, retry. - Return the buffered payload.