On 2 Jun 2022, at 7:56, Johan via digitalmars-d-ldc wrote:

atomicFence only works for ordering memory operations on a single thread, not ordering between threads.

atomicFence should work across threads as well; it inserts actual processor fences as necessary, in addition to the requisite effect on compiler optimisations.

However, in practice, code using standalone fences often harder to make sense of than that using atomic loads/stores, unless the relevant accesses are explicitly documented in enough detail. Just sprinkling atomicFence over an existing code base to make it thread-safe is pretty much guaranteed to fail. Thus, preferring atomic loads/stores is very sound advice in practice.

(There are also fences that are effectively for compiler optimisations only and usually go by volatile fences or signal fences; perhaps that’s what Johan was thinking of.)

— David