Classic Concurrency Problems
A small set of concurrency puzzles has been taught for decades: philosophers sharing forks, a barber who naps between customers, readers and writers sharing a file. They sound like riddles, but each one is a minimal model of a real bug. The philosophers are a deadlock. The barber is a missed wakeup. The readers and writers are starvation. Interviewers ask them because a short puzzle shows quickly whether you can reason about threads, not just use a thread-safe library.
This post walks through the classic problems one by one: what the setup is, what goes wrong with the obvious solution, and the standard fix. Each one has its own practice problem with real threads; here we focus on the shared ideas, so you can recognize the shape when it shows up in a new disguise.
💡 Why this matters in an interview: these problems are small enough to code in 20 minutes, and every one of them has a trap. Naming the trap ("this naive version deadlocks because all five can hold one fork") before you fix it is what earns the credit.
The Map
Every classic problem isolates one failure mode and one tool. Learn the pairs and you will recognize them in real designs.
| Problem | The setup | The trap | The standard tool | Practice |
|---|---|---|---|---|
| Bounded buffer | producers and consumers share a fixed-size queue | busy waiting, missed signals | lock + two condition variables | Bounded Blocking Queue |
| Print in order and friends | threads must run steps in a fixed order | the order is not guaranteed by start order | semaphores as signals | Coordinate Threads in Order |
| Dining philosophers | five threads each need two of five shared locks | deadlock, then starvation | lock ordering, or a limit on diners | Dining Philosophers |
| Readers-writers | many readers or one writer at a time | writer (or reader) starvation | read-write lock with a preference rule | Read-Write Lock |
| Unisex bathroom | one group at a time, limited capacity | the other group starves | group-aware condition + turns | Unisex Bathroom |
| Sleeping barber | a server sleeps when idle, clients wait or leave | missed wakeup | condition variable checked under the lock | Sleeping Barber |
| Traffic intersection | only one road may have the green light | two roads green at once | one lock around switch-and-cross | Traffic-Light Intersection |
The tools themselves (locks, semaphores, condition variables) are explained in Concurrency Fundamentals and Thread Coordination. Here we apply them.