Threads and Cores: How the Operating System Manages Workloads

Cores and Threads in Operating System

·

3 min read

Threads and Cores: How the Operating System Manages Workloads

When you look at your computer's specs, you might see something like a 16-core, 32-thread CPU. It sounds like a lot of power (in-fact it is powerful 💪😜), but what exactly does that mean, and how does the operating system handle all those threads?

Let’s break it down:


What Are Cores and Threads?

  • Cores: Think of cores as the brains of your computer. A core can execute tasks (instructions) from programs independently. So, a 16-core CPU can technically work on 16 tasks at once.

  • Threads: A thread is the smallest unit of a process (A process is defined as the execution of a program). Modern CPUs, with technologies like Intel's Hyper-Threading or AMD's Simultaneous Multi-Threading (SMT), can process multiple threads on each core.
    For example, a 16-core CPU can handle 32 threads (2 threads per core), like the AMD Ryzen 9 7950X, while Intel Core i9-14900K can also handle 32 threads (24 cores, 32 threads) but the CPU core’s architecture is different.

[the above image illustrates Intel’s hyper-threading (intel’s way of saying multi-threading) architecture]

Now, you might wonder, how does an operating system (OS) manage this many threads, especially when your computer can have hundreds running at once?


The Operating System’s Role in Scheduling Threads

The answer lies in thread scheduling, which is how the operating system decides which thread gets to run at any given time. Since CPUs can only handle a limited number of threads simultaneously (equal to the number of cores and their logical threads), the OS must carefully allocate time for each thread to run.


Time-Slicing: The Magic Behind Multitasking

The OS uses a technique called time-slicing to manage multiple threads on a limited number of cores. Time-slicing works like this:

  1. Divide CPU Time: The OS allocates small "time slices" (milliseconds) for each thread.

  2. Switch Threads: As each time slice ends, the OS stops the current thread and switches to another. This process happens so quickly that it gives the illusion that multiple threads are running simultaneously.

  3. Efficiency: Even though only a few threads can be executed at any moment, the OS ensures all threads get a turn, giving the impression of multitasking.

This scheduling happens rapidly enough that you never notice the switching it feels like every program and task is running at the same time!

Why Does This Matter?

While a 16-core, 32-thread CPU can only truly handle 32 threads simultaneously, thread scheduling ensures hundreds of threads can share CPU time seamlessly. This is why your PC feels responsive, even when running multiple apps.


Conclusion

Your 16-core, 32-thread CPU is a multitasking powerhouse 💪. Thanks to clever OS scheduling, it can handle far more than 32 threads, ensuring smooth performance for everything from gaming to rendering.

In the upcoming blog posts in this series, we’ll explore more about threads and thread-management. Stay tuned!