Synchronization and deadlock

Making threads take turns with locks and semaphores, the classic buffer problem, and how a system gets into, avoids and recovers from deadlock.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Synchronization: locks and semaphores Intermediate

    The critical-section problem and its three rules, Peterson's solution, hardware atomic instructions, mutex locks, semaphores, and the producer-consumer, readers-writers and dining-philosophers problems.

  2. 2

    Deadlock Intermediate

    When processes wait for each other forever: the four conditions, resource-allocation graphs, prevention, avoidance with the banker's algorithm, and detection and recovery.

Module practice

Module quiz

1. Which of these is NOT one of Coffman's four conditions for deadlock?
2. What does a semaphore with value 0 do to a thread that calls wait?
3. In the producer-consumer solution, what is the starting value of the semaphore empty for a buffer of N slots?
4. What is a safe state in the banker's algorithm?
5. In a wait-for graph with one copy of each resource, P0 waits for P1, P1 for P2 and P2 for P0. What is the situation?
6. Two threads lock A then B, and B then A. What is the cleanest fix?

‹ CPU schedulingMemory: allocation, paging and virtual memory ›