IT lexicon › Programming › Reader-writer problem

Reader-writer problem

Programming På svenska → Updated: 2026-11-16

A classical synchronization problem where multiple readers can share a resource simultaneously, but writers require exclusive access and must block all other readers and writers.

The reader-writer problem illustrates a common pattern: many threads read the same data concurrently, but when one thread writes, all others must pause. The problem has two classic versions: readers-prefer (writers wait even if readers keep arriving) or writers-prefer (readers wait until the writer finishes). Fair (first-come-first-served) solutions exist to prevent starvation. Solutions employ semaphores, monitors, or modern lock-free structures like stamped locks.

The classic example is a database: many read transactions run in parallel, but a write transaction needs everyone's attention. Poor locking here can become a severe bottleneck.

← Back to the lexicon