How do memory fences/barriers among threads interact with fences/barriers in other threads?

What is the interaction of memory fences in different threads?

More particularly does a memory fence in a thread only prevents the reordering of instructions within the thread or there is there synchronising among the threads like one thread waits until the corresponding fence is reached in another thread? What happens is multiple threads have the same type of fence and multiple threads have paired fences? What type of fences needs to pair together among threads and how are they used? What are the effects if the code with memory fences is run in a single-threaded fashion?

Upvotes: 1

Views: 538

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 365832

A memory barrier is nothing like the tag.

Memory barriers only order the local core's own accesses to coherent shared memory, because that's all that's needed to be able to recover sequential consistency. There is no direct interaction with other threads / cores.

If you want synchronization between threads, use release/acquire ordering. https://preshing.com/20120913/acquire-and-release-semantics/

Upvotes: 2

Related Questions