Skip to content

Shared memory

Readers, writers and starvation

A lock that lets readers share, and the writer that waits for a gap that never comes.

10 minutes · reader-writer lock · starvation · fairness

Fairness is a policy, not a property

A reader-writer lock lets any number of readers hold it at once and gives a writer exclusive access. On a read-heavy workload that is a large win, and it comes with a cost that is easy to miss: nothing in the basic design gives a waiting writer priority over an arriving reader.

On a quiet system that is invisible. On a busy one, readers overlap continuously, the lock is never free of them, and the writer waits indefinitely — not deadlocked, not blocked on anything in particular, just always second in line. Starvation is a liveness failure, and it does not show up as an error anywhere.

Everything you do here stays in this browser.