- Producer owns
head(only producer writes it), consumer ownstail(only consumer writes it). headandtailare separated onto different 64‑byte cache lines with padding to prevent false sharing and cache-line ping‑pong.
- Logical counters:
head= next write index,tail= next read index - Empty:
head == tail - Full:
head - tail == size - Fast wrap (size is power of 2):
slot = index & (size - 1)
- Push
- write:
buf[head&mask] = val - publish: atomic store
head = head+1
- write:
- Pop
- observe: atomic load
headto ensure data exists - read:
val = buf[tail&mask] - free: atomic store
tail = tail+1
- observe: atomic load
- No underflow:
tail <= head - No overflow:
head - tail <= size
(Checked via TLC model checking in RingBuffer.tla under a finite bound.)

