C++ memory orderings

I just learned about memory orderings today, and I'm not sure I fully understand it. Basically the standard library provides six std::memory_order enumerators that fit into three categories. (1) Sequential consistent ordering, (2) Acquire-release ordering, and (3) relaxed ordering.

Could someone briefly explain the practical uses of all three ordering categories? Such as examples where I would want to prefer one ordering over the other?
Last edited on
This seems like pretty esoteric stuff to me. It looks like it deals with details of parallel processing and optimization, telling the compiler what optimizations it can still perform in the face of multiple threads.

Or maybe I've got it all wrong. I'm sure someone will correct me if so.

When in doubt, I just declare a variable volatile.
I would also like to someone to explain how this memory models work and what's their purpose.

they are in standard for some time already, but nobody seems to be talking about them.

It looks like it deals with details of parallel processing and optimization, telling the compiler what optimizations it can still perform in the face of multiple threads.


It deals with the ordering of atomic operations between threads, but I'm just confused on when they would be applicable in real code to see a performance difference. Right now my understanding of them is rather abstract and I want to see some real-life connections.
Topic archived. No new replies allowed.