---
title: "Discussion on \"Instruction Reordering: Your Code Doesn’t Always Run in the Order You Wrote It\" | Hashnode"
description: "Discussion on \"Instruction Reordering: Your Code Doesn’t Always Run in the Order You Wrote It\". When writing code, you naturally expect instructions to run one after the other in the exact order they appear. For example:\nx=1;\ny=2;\n\nYou’d expect x = 1 to complete before y = 2 starts.\nBut in reality, modern CPUs and compilers don’t always execute..."
url: "https://hashnode.com/posts/instruction-reordering-your-code-doesnt-always-run-in-the-order-you-wrote-it/68923331d9d47da9240db276"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Instruction Reordering: Your Code Doesn’t Always Run in the Order You Wrote It](https://nihcas.hashnode.dev/instruction-reordering-your-code-doesnt-always-run-in-the-order-you-wrote-it?utm_source=hashnode&utm_medium=feed)

When writing code, you naturally expect instructions to run one after the other in the exact order they appear. For example: x=1; y=2; You’d expect x = 1 to complete before y = 2 starts. But in reality, modern CPUs and compilers don’t always execute...

Aug 5, 2025 · 5 min read · nihcas.hashnode.dev  
Read the article

-   [#compileroptimization](https://hashnode.com/tag/compileroptimization)
-   [#multithreading](https://hashnode.com/tag/multithreading)
-   [#memory-barrier](https://hashnode.com/tag/memory-barrier)
-   [#atomic-operations](https://hashnode.com/tag/atomic-operations)

## Written by

[Sachin Tolay](https://hashnode.com/@tolaysachin)

@tolaysachin · Burnaby

  
[View profile](https://hashnode.com/@tolaysachin)

I am here to share everything I know about computer systems: from the internals of CPUs, memory, and storage engines to distributed systems, OS design, blockchain, AI etc. Deep dives, hands-on experiments, and clarity-first explanations.

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
