logoalt Hacker News

erickpintortoday at 2:54 PM3 repliesview on HN

Great post!

Would you mind expanding on the correctness guarantees enforced by the atomic semantics used? Are they ensuring two threads can't push to the same slot nor pop the same value from the ring? These type of atomic coordination usually comes from CAS or atomic increment calls, which I'm not seeing, thus I'm interested in hearing your take on it.


Replies

erickpintortoday at 3:01 PM

I see you replied on comment below with:

> note that there are only one consumer and one producer

That clarify things as you don't need multi-thread coordination on reads or writes if assuming single producer and single consumer.

show 1 reply
dalvrosatoday at 3:01 PM

Thanks! That's not ensured, optimizations are only valid due to the constraints

- One single producer thread

- One single consumer thread

- Fixed buffer capacity

So to answer

> Are they ensuring two threads can't push to the same slot nor pop the same value from the ring?

No need for this usecase :)

loegtoday at 3:05 PM

This is a SPSC queue -- there aren't multiple writers to coordinate, nor readers. It simplifies the design.