liveBook · Manning

Reader-writer problem

As explained in Object-Oriented Software Design in C++

The reader-writer problem is a concurrency coordination problem involving concurrent readers and writers of shared data with potentially conflicting access requirements.

The reader-writer problem coordinates concurrent access to shared data: one writer may modify it exclusively, while multiple readers may read it together when no writer is active. section 16.2.2

In C++, shared mutexes express the two access modes:

  • Use unique_lock with shared_mutex for writing; it excludes every other reader and writer. section 16.2.2
  • Use shared_lock with shared_mutex for reading; multiple readers may hold the lock together, but writers cannot enter. section 16.2.2

Technicians and loggers

A shared meter is updated by three technician threads and observed by three logger threads. A technician locks it exclusively while setting its value; otherwise, several loggers can read and log the current setting simultaneously. section 16.2.2

How Object-Oriented Software Design in C++ covers it

How deep it goes
Defines exclusive and shared locking with a worked C++ example, without detailing synchronization internals beyond lock behavior.
Examples
Uses a shared meter, technician writers, logger readers, lock-scoped C++ methods, and concurrent program output.
What it assumes
Assumes basic threads and shared data, while introducing mutex-protected critical regions and reader-writer locking.
What you can do after
Apply it via C++ shared_mutex, unique_lock, and shared_lock to protect shared data with distinct read and write access.
How it connects
Connects shared resources, mutexes, critical regions, multithreading, 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 Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.