Why std::memory_order_seq_cst is often overkill for single-producer single-consumer queues:
When writing a lock-free queue:
- Producer: Writes payload to buffer, then performs
tail.store(newTail, std::memory_order_release). - Consumer: Loads
tail.load(std::memory_order_acquire), then reads payload.
release guarantees that all prior memory writes (the buffer data) are visible to any thread that executes an acquire load on that same atomic variable. On x86/x64, hardware already enforces TSO (Total Store Order), so acquire/release loads/stores compile to plain mov instructions with zero mfence penalty!