Task Switching Thousands of Times Every Second!
It feels as though the computer is playing music and compiling code at the exact same instant. In reality, the CPU switches between applications every 5 to 10 milliseconds at blinding speed.
This high-frequency scheduling magic is known as Preemptive Multitasking—orchestrated continuously by the operating system's Scheduler.
1–5. Program vs. Process and Memory Isolation
Program (Inert File)
A collection of stored instructions on disk (such as chrome.exe). It consumes no CPU cycles or active RAM on its own.
Process (Living Entity)
The active instantiation of a program in RAM. Contains its own virtual memory space, code, data, heap, stack, and system resource handles.
6–9. Thread: The Worker Within a Process
If a process is an entire office building, a Thread is a worker inside that office. All threads share the building's common resources (memory space) but execute tasks independently.
Thread Task Distribution in a Browser:
- 🎨 UI Thread: Handles mouse clicks, scrolls, and visual responsiveness.
- 🌐 Network Thread: Downloads images, stylesheets, and web pages in the background.
- ⚙️ Worker Thread: Processes heavy JavaScript computations and data parsing.
Race Conditions & Locks:
Because threads share identical memory addresses, two threads writing to the same variable simultaneously can corrupt data. To prevent this, developers use synchronization primitives like Mutexes and Locks.
12–13. Concurrency vs. Parallelism
Interleaving multiple tasks rapidly on a single core to make forward progress on all of them.
Executing multiple threads simultaneously on distinct physical CPU cores at the exact same moment in time.
14–18. CPU Scheduler and Context Switch
The OS Scheduler determines how much execution time (Time Slice or Quantum) each thread receives on a CPU core.
- When Thread A's time slice expires, a hardware timer interrupt fires.
- The CPU's registers and Program Counter (PC) are saved into Thread A's context block in RAM (Save State).
- The saved register state of the next ready thread (Thread B) is loaded into the CPU (Restore State).
- The CPU resumes execution from Thread B's restored Program Counter.
23–27. Process Lifecycle States
31–34. SMT & Hyper-Threading: Two Threads per Core
When a processor specification lists 8 Cores / 16 Threads, it means each physical execution core maintains two sets of register states and instruction pointers—known as Hyper-Threading on Intel and broadly termed SMT (Simultaneous Multithreading).
40–41. Inter-Process Communication (IPC)
46–47. Master Software-to-Hardware Execution Pipeline
🧠 Key Takeaways
- Program vs Process: A program is passive code stored on disk; a process is an active executing instance in RAM.
- Thread: An independent path of execution within a process sharing the same address space.
- Process Isolation: Each process resides within private virtual memory to prevent memory corruption or unauthorized access.
- CPU Scheduler: Manages time slices and orchestrates sub-millisecond context switches to deliver smooth multitasking.
- Concurrency vs Parallelism: Rapid interleaving on shared cores vs true simultaneous execution across separate cores.
- SMT / Hyper-Threading: Duplicates architectural state on physical cores to maximize pipeline utilization and throughput.
Lesson 17 — Computer Graphics & GPU: From Binary to Screen Pixels
Learn how millions of pixel colors, 3D rendering pipelines, frame buffers, and thousands of parallel GPU cores generate vivid imagery on your display.