What does a std::atomic store with memory_order_relaxed actually guarantee?
Correct answer
B. Atomicity of the operation only, with no ordering against other accesses
20 views
B. Atomicity of the operation only, with no ordering against other accesses
20 views
memory_order_relaxed promises that the operation is indivisible and that a single atomic object has a consistent modification order, but it imposes no ordering on surrounding loads and stores. Another thread can therefore observe relaxed values in an order that looks impossible in the source. Use a release store paired with an acquire load when the atomic publishes ordinary data, such as a ready flag guarding a buffer.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.