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.