Here are the sequence of steps that will starve writers in favor of readers:
r_go
signaling semaphore. A writer enters next and delays on the w_go
signaling semaphore.
dr > 0
, it increases nr
by one signals r_go
; it then unlocks mtx
and drops out of the
database.
r_go
after adding one to dr
and unlocking mtx
.
r_go
that has been signaled drops out of the wait()
and locks mtx
. It reduces dr
by one and, because there are more
delayed readers, signals the next reader waiting on r_go
. It then goes on
to complete the rest of the entry protocol and enters the database.
If we assume always at least two readers in the database, each exiting reader never is the last reader in the database and so will never release the waiting writer.
This page last modified on 26 June 2003.