Portable equivalent of asm volatile("" ::: "memory")?

Viewed 80

In C, is there a compiler-neutral way to issue a compiler-level memory barrier, like gcc's asm volatile ("" ::: "memory");? The exact behaviour that I want is to prevent the compiler from re-ordering memory accesses across the barrier (so if a value is copied to a register before the barrier, I want to make sure it is re-read from memory after the barrier). I'm thinking that stdatomic.h's atomic_signal_fence or atomic_thread_fence might be able to achieve this, but I'm not familiar enough with them to know for sure. Thanks.

0 Answers
Related