In computer architecture, memory ordering is the order of accesses done to memory by a CPU. This has no implication for single-threaded code (which reorders in a correct way), but is important in multithreading and with memory-mapped IO. There are two types of orders:

  • Strong (or sequentially) consistent — when the order of operations cannot change, or when these changes have no visible effect on any thread. x86-64 is a strongly-ordered architecture, and it preserves the order of loads and stores in most cases.
  • Weak (or relaxed) — when one thread cannot predict the order of operations arising from another thread. ARM is a weakly-ordered architecture.

In weakly-ordered architectures, we use memory barriers to enforce orders.