Skip to main content
PRISM

Mutexes

foundational · asked in almost every interview

The lost-update program with a lock around it. Twenty interleavings become two, and the losing orderings stop existing rather than becoming unlikely.

Enumerating the interleavings

What this shows

A lock removes orderings from the space. The critical section must span the whole read-modify-write — guarding only the write leaves the window exactly where it was.

Why it is asked

Everyone says "add a mutex". Being able to say what happens to the interleaving space, and where the section must start and end, is the difference.

In an interview

Everyone says "add a mutex". Being able to say what happens to the interleaving space, and where the section must start and end, is the difference.

  • locks
  • critical section
  • mutual exclusion

Run these next

The rest of mutual exclusion