← Lessons

quiz vs the machine

Silver1080

Concurrency

The Mutual Exclusion Requirements

The exact guarantees a mutual exclusion mechanism owes you, and the failure modes it must avoid.

4 min read · intro · beat Silver to climb

More than just one at a time

Saying a lock provides mutual exclusion is only the start. A trustworthy mechanism owes you several guarantees beyond keeping a single thread inside the critical section.

The requirements

  • Safety at most one thread is in the critical section at any instant
  • No deadlock the threads as a group always make some progress and never freeze waiting on each other
  • No starvation any individual thread that wants to enter eventually does, not just the group
  • No assumptions about timing correctness must not depend on how fast threads run or how many processors exist

Common failure modes

A broken scheme can be fast but unsafe, letting two threads slip in together under the right interleaving. Another can be safe but deadlock prone, where threads politely defer to each other forever. A third can be safe and deadlock free but starve one unlucky thread while others keep cutting ahead. A correct mechanism avoids all three.

Key idea

Mutual exclusion means safety plus freedom from deadlock and starvation, with no reliance on relative thread speeds.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is avoiding deadlock not enough on its own?

2. What does no timing assumptions require?