I'm trying to understand the difference between Release/Acquire and SeqCst but can't come up with a scenario where Release/Acquire would fail while SeqCst would work. Could someone provide an example where SeqCst is necessary and Release/Acquire wouldn't provide the desired consistency?
I recommend Chapter 3 of the Rust Atomics and Locks book, in particular the section on Sequentially Consistent Ordering. The book points out:
SeqCst
ordering is almost never necessary in practice. In nearly all cases, regular acquire and release ordering suffice.
Virtually all real-world uses of
SeqCst
involve a similar pattern of a store that must be globally visible before a subsequent load on the same thread. For these situations, a potentially more efficient alternative is to instead use relaxed operations in combination with aSeqCst
fence, which we’ll explore next.
The only case I've encountered where I needed SeqCst
was when working with vector clocks in a rather over-complicated system. Each logical clock had to be stored in an atomic because it was shared between threads on a node, and I needed (for other reasons) a hard guarantee that within a node, I did not ever generate a vector clock that appeared to go backwards for one or more nodes.
The easiest way to implement this is to make the per-node logical clocks SeqCst
; then, all threads in my node agree on a total order for the vector clock. The better thing to do would have been to make the system much simpler
Thanks for your response, @hax10 . I'm currently reading the Rust Atomics and Locks book, which is where my question came from.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.