Semaphores

The dinging philosophers problem

First attempt

First attempt (Deadlock)

Solution 1 : Break the symmetry

Solution 2 : Limit the usage of resources

Starvation

Preventing deadlocks: Order of resources

Preventing deadlock: Break the chain

Producer-Consumer

Unbounded buffers

...

Bounded buffers

One-slot buffer

General N-slot buffer

code

Preparing for blocking

Readers-writers problem

Summary