Threads for Operating Systemss
Threads are separate flows of execution inside one process that share the same address space. Sharing data makes races possible, so threads need locks, condition variables and semaphores to coordinate. Getting this wrong leads to race conditions, deadlock and lost wakeups, which are the central concurrency problems.
Stage: Concurrency · Part of the Operating Systems roadmap · Last reviewed 19 November 2026
What to learn in Threads
- Create threads with pthreads and join them
- Protect a shared counter using a mutex lock
- Use a condition variable to build a producer and consumer queue
- Identify the four conditions required for a deadlock
- Explain how semaphores generalise locks and signals
Threads interview questions
What is a race condition?
A race condition happens when the result depends on the unlucky timing of threads accessing shared data, such as two threads incrementing one counter and losing an update. Placing the access in a critical section guarded by a lock removes it.
What are the four conditions for deadlock?
Mutual exclusion, hold and wait, no preemption, and circular wait. All four must hold together. Breaking any one prevents deadlock, and the common fix is acquiring locks in a fixed global order to avoid circular wait.
Where Threads fits in the Operating Systems roadmap
Threads belongs to the Concurrency stage (intermediate level). Threads and synchronisation.
Back to the full Operating Systems roadmap