What it does: Executes instructions using the Fetch-Decode-Execute cycle.
Key Specs:
Cores: Independent processing units inside the CPU. More cores = more true multitasking.
Clock Speed (GHz): The number of cycles per second. Higher is generally faster.
Cache (L1/L2/L3): Tiny, ultra-fast memory on the CPU for frequently used data.
Process vs. Thread
Feature
Process (e.g., Google Chrome)
Thread (A Tab in Chrome)
Analogy
A self-contained Kitchen
A Cook working in the kitchen
Resources
Has its own private memory & resources
Shares memory with other threads in its process
Weight
Heavyweight (slow to create)
Lightweight (fast to create)
Isolation
Isolated from other processes (stable)
Not isolated from its sibling threads
Unit Of
Resource Ownership
Execution (What the CPU runs)
The Relationship with the CPU
The Operating System (OS) Scheduler is the manager.
The OS schedules Threads, not processes, to run on CPU cores.
Single-Core CPU: Achieves multitasking via Concurrency (fast switching/time-slicing). Gives the illusion of parallel execution.
Multi-Core CPU: Achieves True Parallelism. A 6-core CPU can run 6 threads at the exact same time.
How Many Threads Can Run?
At the Same Time (In Parallel):
The number is limited by the CPU’s Logical Cores
Rule: 1 Thread per Logical Core.
Example: A 6-core CPU without Hyper-Threading runs 6 threads in parallel. A 6-core CPU with Hyper-Threading runs 12 threads in parallel.
In Total (Existing in the System):
The number is limited by RAM and OS configuration.
Can be tens of thousands.
Most of these threads are either Ready (waiting for a CPU core) or Waiting/Blocked (waiting for I/O like disk or network).
Finding the Optimal Thread Count (Performance Tuning)
The ideal number of threads depends entirely on the type of workload
Workload Type
Description
Optimal Threads on a 6-Core CPU
Reason
CPU-Bound
Constant calculation (e.g., video rendering). The CPU is the bottleneck.
6
Maximizes core usage without the waste of context-switching.
I/O-Bound
Frequent waiting (e.g., file downloads). The disk/network is the bottleneck.
>> 6 (e.g., 20-100+)
Hides I/O latency. While one thread waits, another uses the CPU.
The Ultimate Rule:Don’t Guess, Measure! Start with a number of threads equal to your core count and benchmark your application, increasing the thread count to find the “sweet spot” for your specific task.