Hi everyone. Your favourite writer is back (Stealing my sister's name cause I can 😔). Today's discussion is going to be about CPU, Processes and Threads. By the end of this conversation, we should be able to understand:

  • How a CPU executes instructions.
  • CPU cores, clock speed, and vCPUs.
  • A process and how it differs from a program.
  • Thread and why applications use multiple threads.
  • Multitasking, concurrency, and parallelism.
  • How operating systems schedule CPU work.
  • How this all applies to cloud servers.

On y va?

The CPU executes instruction but what does it actually mean to execute an instruction?

Let's imagine a simple scenario.

You open the calculator on your computer, type in 10 + 15, press the equals button, and voilà! You get 25. très bien.

Simple, right?

But have you ever wondered how your computer knew what you wanted it to do?

How did it know you wanted to add two numbers together? How did it calculate the result? And how did that result appear on your screen?

Well, here's the interesting part: your CPU doesn't actually understand what you're doing the way you do.

When you press those buttons, the calculator application processes your input and executes instructions that eventually cause the CPU to perform the necessary operations.

So, what looks like a simple 10 + 15 = 25 involves several operations happening behind the scenes.

But how exactly does the CPU execute those instructions?

To understand that, we need to look at something called the Fetch–Decode–Execute cycle.

The instruction cycle
A simplified CPU instruction cycle has three stages:

FETCH - DECODE - EXECUTE

Fetch: The CPU retrieves the next instruction, usually through its memory hierarchy.

Decode: The CPU determines what operation the instruction represents.

Execute: The CPU performs the operation, such as addition, comparison or data movement.

Modern processors are more complicated. They use pipelines, caches, branch prediction and other optimizations, but this simplified cycle is our starting point.

  • Registers: These are tiny storage locations used directly by CPU instructions.
  • CPU cache: Fast memory that keeps frequently or recently accessed data close to the processor.
  • RAM: Larger working memory that is volatile, it clears totally when the computer is turned off or shut down, it is generally slower to access than CPU cache.
  • SSD: Persistent storage, much slower to access than registers or cache.