Multicore & Synchronization

What is the role of a memory barrier (fence) instruction?

  1. AIt guarantees that memory operations before the barrier become visible to other cores before those after it
  2. BIt physically partitions memory and forbids access
  3. CIt stops the program until every thread arrives
Show answer and explanation

Answer: A. It guarantees that memory operations before the barrier become visible to other cores before those after it

CPUs can reorder memory operations, so passing data to other cores in a fixed order requires an instruction that prevents it. A full memory barrier completes all earlier reads and writes, making the writes visible to other cores, before later ones are performed. There are also lighter barriers that order only selected kinds of reads and writes. Lock acquisition and release include this barrier effect, which is why variables protected by a lock are passed correctly.

  • A. Correct. It stops memory operations from being reordered across it.
  • B. Forbidding access is done by page protection and similar.
  • C. That is barrier synchronization among threads.