Or, at least, a quasi-fair solution. Once the exiting writer locks mtx
it
stays locked until the last waiting reader enters the database. Any new
readers attempting to enter the database will block while locking mtx
and
will be delayed until all currently waiting readers have entered the database.
When the last reader leaves the database, it will release the next waiting
writer, and the cross-release code ensures a quasi-fair solution.
The solution is only quasi-fair because we have no control over semaphore
release behaivor. It may be that there is some unfortunate writer blocked on
w_go
that never gets selected to continue execution. Although some writer
always gets selected for execution, our writer never gets selected, violating
fairness (and once again illustrating the difference between safety
property (every competition produces a winner) and a liveness property
(every competitor eventually wins).
This page last modified on 26 June 2003.