Readers/Writers Workbench
Message Passing Solution
The readers/writers (RW) problem is a classic synchronization problem. A set of processes called readers and a set of processes called writers share a common database (DB). The readers just read the value stored in the DB and the writers change the value of the DB. The reader executes an infinite loop in which it reads the value of the database and the writer executes an infinite loop in which it creates a new value and stores it into the DB. The following important conditions have to be satisfied
by the readers and writers:
- At most one writer can be updating the DB at any time. While a writer is updating the DB, no readers are allowed to read the contents of the DB.
- One or more readers may be reading the DB at the same time. While there are readers reading the DB, no writers are allowed to modify the value of the DB.
This workbench displays a solution to the RW problem using message passing. In this case, the DB is controlled by a database server process to which the readers and writers send read and write requests. Our workbench shows three readers (portrayed as books) and two writers (portrayed as pencils). Colored bullets indicate the position in the reader or writer code for each process. A box labeled DB shows the value of the DB. Readers and writers enter this box when they are
allowed to read/write the DB. You can execute the workbench in a step-by-step mode by pushing the step button for each individual process or by moving each process one step forward (STEP button). You can also execute the workbench in a continuous mode by pushing the START button. You will see controls that allow you to change the animation speed.
Workbench