Re:Yes, You Have Been Writing SPSC Queues Wrong
by gpderetta on Thursday December 15, 2016 @08:29PM
(#13190357)
You can specify the memory ordering of operations to get the desired fences.
For an spsc queue just load aquires and store releases are sufficient and will have no overhead at all on x86.
Don't use operator++ to increment ( it will use an expensive lock xadd) just code the explicit load + add + store sequence. It is safe on this specific case.
On Intel you would not care about the missing slot when you have 256GB memory available.
I've added the atomic<> in the github and updated the article as well.
However with atomic<> it adds an mfence instruction which is not really necessary and might add a ton of latency.