Status: ✅ COMPLETE
Scope: The units of work inside a process: what a thread is, how Windows schedules, prioritises and switches threads, how threads cooperate safely, what goes wrong when they do not, and how thread pools save effort
Time to complete: 90–120 minutes of reading + lab
Prerequisites: Chapter 2 (CPU Internals), Chapter 3 (RAM and Memory Internals), and the chapter on processes just before this one
What you'll know after: How a thread differs from a process, how Windows chooses which thread runs on which core, what thread states and priorities mean, what a context switch costs, and how to avoid race conditions and deadlocks
INTRODUCTION
A process is only a container: it owns memory and handles but runs nothing by itself. The things that actually run are threads. Every program you use is a team of threads that the operating system rapidly places onto your CPU's cores, thousands of times each second.
This chapter uses plain words. Every technical term is explained the first time it appears. It uses a real photo of a modern CPU die, and many ASCII diagrams (timelines of threads taking turns, a state diagram, a deadlock cycle and a race condition) to show what is going on.
This chapter explains:
- What a thread is and how it differs from a process
- The main thread, worker threads, and how threads are created and ended
- How the scheduler shares cores using time slices and preemption
- The states a thread moves through, and how to see them
- Priorities (0–31), boosts, real-time threads and priority inversion
- What a context switch saves, and why it is not free
- Locks and signals: mutex, semaphore, event, critical section, SRW lock, condition variable
- Race conditions, deadlock, livelock and starvation, and how to find and avoid them
- Thread pools and why Windows has one built in
CHAPTER OUTLINE
- Section 1: What is a Thread?
- Section 2: Main Thread and Worker Threads
- Section 3: Thread Scheduling
- Section 4: Thread States
- Section 5: Thread Priority
- Section 6: Context Switching (Thread-Level)
- Section 7: Thread Synchronization
- Section 8: Concurrency Problems
- Section 9: Thread Pools
- Practical Lab: Observing Threads
- Knowledge Check
Chapter Status: Complete
Estimated reading time: 100 minutes
Practical time: 30 minutes
Knowledge check time: 30 minutes