Hardware makes only a few single instructions atomic, but real critical sections are bigger (read a balance, check it, write it back). You can’t make an arbitrary multi-step region physically indivisible, but you can stop anyone from looking while it runs.

Mutual exclusion: guarantee that at most one thread is inside the region at a time. Then no other thread is ever positioned to observe its half-done middle. The region is still physically divisible but the divisibility becomes unobservable. It is observably atomic: indistinguishable from atomic to every other thread.

This is the first of the two guarantees a lock provides. Note precisely what it does and doesn’t do:

  • It does not make the instructions physically atomic (the hardware still sees separate ops).
  • It does not stop the scheduler from interleaving the threads generally — the other thread runs freely, it just can’t enter this region concurrently.
  • Fairness (acquiring in request order) is a separate, optional property, not what mutual exclusion is.

It is tempting to think this is the whole story of a lock. It is not — mutual exclusion alone is necessary but not sufficient. See the store-buffer litmus test to see why.

See also

References

Questions

flashcards/stem/os

How does mutual exclusion make a divisible critical section “act atomic”?::By ensuring only one thread is inside at a time, no other thread can observe the region’s half-done middle — it becomes observably atomic without being physically indivisible

Is mutual exclusion the whole story of a lock?::No — it is necessary but not sufficient; a program with no concurrent region entry can still break from visibility/ordering issues

Mutual exclusion makes the region’s divisibility unobservable, not physically indivisible.