← Lessons

quiz vs the machine

Gold1420

Concurrency

The CPU Out of Order Execution

How processors execute instructions early yet appear in order to one thread.

6 min read · core · beat Gold to climb

Executing ahead of time

Modern processors do not run instructions strictly in program order. An out of order core fetches many instructions, finds ones whose inputs are ready, and executes them early to keep its many execution units busy while slower operations, like cache misses, are pending.

Keeping a single thread correct

Even though execution is scrambled, a single thread sees its own results in order. The core tracks dependencies and uses a reorder buffer to retire results in program order, so register and memory effects become architecturally visible in sequence for that thread.

  • Instructions execute when operands are ready, not when fetched.
  • Results retire in program order from the reorder buffer.
  • Mispredicted speculative work is squashed before it becomes visible.

Why other threads still see reordering

The in order illusion holds only for the issuing thread. Other threads can observe the effects of memory operations in a different order, because stores drain through buffers and caches asynchronously. That is exactly why memory models and barriers exist: to restore ordering that out of order execution and store buffers otherwise hide.

Key idea

Out of order cores execute instructions early but retire them in program order for the issuing thread, while other threads can still observe reordered memory effects unless barriers intervene.

Check yourself

Answer to earn rating on the learn ladder.

1. How does an out of order core keep a single thread correct?

2. Why can other threads still see reordering?