The rules of the readers-preferred shared record are these:
A solution to this problem in Memo uses three folders and an extra status record in addition to the data record.
- status folder, holding the status record
- read folder, where the data record is placed while being read and between accesses
- write folder, where the data record is placed to give it to a writer.
- nr, number of readers waiting for the record or reading.
- nw, number of writers waiting or writing.
The algorithms are described in terms of their implementations of the four operations.
start reading.
get the status memo
add one to nr
replace the status memo
get a copy of the data memo from the read folder
end reading
get the status memo
subtract one from nr
if nr=0 and nw>0,
get the data memo from the read folder
put it into the write folder
replace the status memo
start writing
get the status memo
add one to the number of writers
if nr=0 and nw=1
get the data memo from the read folder
replace the status memo
otherwise
replace the status memo
get the data memo from the write folder
end writing
get the status memo
subtract one from nw
if nr>0 or nw=0
put the data memo into the read folder
otherwise
put the data memo into the write folder
replace the status memo
This page last updated 04/06/97