liveBook · Manning

Reader-writer problem

As explained in Software Design for Python Programmers

The reader-writer problem is a concurrency problem involving shared access where readers may proceed concurrently but writers require exclusive modification access.

The reader–writer problem coordinates shared access when readers may proceed together but writers require exclusive access. A meter simulation models technicians changing a value and loggers reading it. section 16.0 section 16.3.1

A practical synchronization design separates the access rules:

  • Protect meter updates with a mutex so only one technician writes at a time. section 16.3.1
  • Use a semaphore to permit up to three simultaneous logger reads while preventing writes during active reads. section 16.3.1
  • Keep each read or write operation inside its critical region, including the simulated time spent accessing the meter. section 16.3.1

Meter simulation

Three technician threads repeatedly choose settings from 1 through 4 and update the meter. Three logger threads read and print the current setting; their output shows several loggers operating together between exclusive technician updates. section 16.3.1

How Software Design for Python Programmers covers it

How deep it goes
Demonstrates mutex and semaphore coordination through a meter simulation, stopping short of a general reader–writer algorithm.
Examples
Uses technicians writing meter settings, loggers reading them, and a timed execution trace.
What it assumes
Assumes basic threads and shared-resource access while illustrating mutual exclusion, semaphores, critical regions, sleeping, and busy waiting.
What you can do after
Build it from scratch using Python locks and semaphores to coordinate concurrent readers and exclusive writers.
How it connects
Connects shared resources, critical regions, mutexes, semaphores, threads, and producer–consumer synchronization.

Also explained in

Compare how 3 books explain reader-writer problem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Design for Python Programmers. The section links point to the parts of the book it draws on.