1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What does a std::atomic store with memory_order_relaxed…

Added 30 Nov -0001

What does a std::atomic store with memory_order_relaxed actually guarantee?

  1. Atomicity only for threads that happen to share the same cache line layout
  2. Atomicity of the operation only, with no ordering against other accesses Correct answer
  3. Atomicity plus release ordering of every preceding write in that thread
  4. Atomicity plus sequential consistency with respect to all other atomics

Correct answer

B. Atomicity of the operation only, with no ordering against other accesses

20 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs