Problem 6: Readers and Writers

The program allows Readers concurrent access to a resource while restricting Writers to exclusive access. Thread access to the shared resource is depicted by a light blue (cyan) arc segment. It is possible by starting the Reader threads at different times to create an execution in which Writer threads never get access to the resource.

When a Reader or Writer thread is paused, you can grab the start or end line of the critical section and move it around, thereby making the critical section larger or smaller.

Problem: when the readers overlap, the writers will starve.

Unable to load applet

 

Exercise:

A policy for reader writer implements the interface ReadWrite.java. The applet (ReadersWriters.java) instantiates a SafeReadWrite policy. It uses a hook method ReadWrite makePolicy(ReaderWriterPanel view) to instantiate the specific reader writer policy. You only need to overwrite this method in subclasses.