1. Dining Philosophers
Teaches: Resource Allocation & Deadlock Prevention.
- Unsafe: If 5 philosophers grab their left chopstick, 0 remain. Everyone waits for the right. Circular Wait causes a system freeze (Deadlock).
- Safe Fix: Use a Semaphore initialized to 4 (a Waiter) so only 4 people can sit at the 5-seat table, guaranteeing one can always eat.
2. Cigarette Smokers
Teaches: Conditional Synchronization (Signaling specific threads).
- Threads shouldn't always wake up sequentially. If an Agent places Paper & Matches on the table, the OS must wake up the specific smoker who has Tobacco.
3. Producer-Consumer (Bounded Buffer)
Teaches: Managing Queues and Capacity Limits.
- Uses 3 Semaphores:
Mutex (Lock), Empty (Counts free slots), Full (Counts used slots).
- Mutex: Ensures only one person modifies the buffer at a time. If the Producer holds the Mutex, the Consumer is blocked.
4. Readers-Writers
Teaches: Shared vs. Exclusive Locks.
- Rule: Multiple Readers can be inside the Database at the exact same time (Shared Lock).
- Writer: Needs exclusive access. If a Writer wants to write, new Readers are blocked, and it waits for the DB to completely empty out.
5. Sleeping Barber
Teaches: Client-Server queues & Dropped Tasks.
- Barber sleeps if no customers. Customer wakes him up.
- If Barber is busy, customers wait in N chairs. If chairs are full, new customers leave the system entirely (Task Dropped/Timeout).