Time to start driving some applets! Download and unzip
the Book Applets zip file.
Go to the book_applets sub-directory and run the applet:
appletviewer ReadWriteFair.html &
Give the Readers low priority (sliders to left) and Writers high
priority; start the Writers first. You will (hopefully) notice that
the Readers can still be starved! This is
because ReadWriteFair.java in concurrency/readwrite
is still not fully fair to the readers!!! Your task is to edit this
to fully implement the fair(er) RW_LOCK monitor (which has an
added requestRead action and an added waitingR component
to the RW_LOCK state, see below).
Note that you do not explicitly implement the requestRead action
in the monitor (in the same way as the requestWrite action
is not explicitly implemented in the existing code.
Compile your file from
the book_applets sub-directory:
javac concurrency/readwrite/ReadWriteFair.java
and re-run the applet as above to check that you have properly
implemented this. Also check the converse situation with Readers having
high priority to see that the Writers now don't get starved.
Hint: you only need to implement the
waitingR component of RW_LOCK; all of the other
4 components are already implemented in the code.
Note: to re-run the applet, you may need access the applet
via your browser, as appletviewer on the CS student system is
rather broken. To do this, open the File Manager in the
book_applets sub-directory and double click on ReadWriteFair.html
.
RW_LOCK = RW[0][False][0][0][False],
RW[readers:0..Nread][writing:Bool]
[waitingW:0..Nwrite][waitingR:0..Nread][readersturn:Bool] =
( when (!writing && (waitingW==0||readersturn))
acquireRead -> RW[readers+1][writing][waitingW][waitingR-1][readersturn]
| releaseRead -> RW[readers-1][writing][waitingW][waitingR][False]
| requestRead -> RW[readers][writing][waitingW][waitingR+1][False]
| when (readers==0 && !writing && (waitingR==0||!readersturn))
acquireWrite -> RW[readers][True][waitingW-1][waitingR][readersturn]
| releaseWrite -> RW[readers][False][waitingW][waitingR][True]
| requestWrite -> RW[readers][writing][waitingW+1][waitingR][readersturn]
).