Rate This Document
Findability
Accuracy
Completeness
Readability

Compiler Memory Fences

The compiler optimizes the generated executable code to some extent, resulting in out-of-order execution or even execution omission.

The following instruction can solve the memory access disorder caused by optimization in the compilation phase.

  • Code on x86:
    // GCC ensures in-order execution of write and read operations issued before and after the following instruction.
    __asm__ __volatile__("" : : : "memory");
  • Alternative for Kunpeng processors:
    __asm__ __volatile__ ("dmb ish" ::: "memory");