Multicore & Synchronization

Which statement is correct about memory operations with acquire and release semantics?

  1. ABoth acquire and release are the heaviest barriers, completely stopping all reads and writes
  2. BAcquire allocates memory and release frees it
  3. CReads and writes after an acquire cannot move before it, and reads and writes before a release cannot move after it
Show answer and explanation

Answer: C. Reads and writes after an acquire cannot move before it, and reads and writes before a release cannot move after it

Taking a lock has acquire semantics and releasing it has release semantics. Operations after the acquire do not leak to before the lock is taken, and operations before the release do not leak to after it is released, so accesses in the protected region stay inside it. With fewer restrictions than a full barrier, which blocks both directions, hardware can keep the remaining reorderings for performance.

  • A. They restrict only one direction, so they are lighter than a full barrier.
  • B. This is unrelated to memory allocation.
  • C. Correct. It is a lighter, one-directional ordering guarantee.
Practice this topic Back to topic

More Multicore & Synchronization questions

  1. In C, why is marking a flag variable shared between threads volatile not sufficient for synchronization?
  2. Why do C11 _Atomic and C++11 std::atomic let programmers specify a memory order?
  3. Which correctly compares coarse-grained locking (one lock for a whole large data structure) with fine-grained locking (separate locks for each part)?
  4. What property does a lock-free algorithm have?
  5. Which describes a critical section?