Memo Shared Records: Writers preferred.

Th Christopher
Memo home page

Memo Prog Tech

The rules of the writers-preferred shared record are these:

A solution to this problem in Memo uses four folders and an extra status record in addition to the data record.

  1. F[0], read folder 0
  2. F[1], read folder 1
  3. F[0,1], status folder
  4. F[0,2], write folder

(A folder name s[i] means its symbol is s and its X array is {i,0,0}; similarly s[i,j] means its symbol is s and its X array is {i,j,0}.)

  1. nr, number of processes reading
  2. wtr, number of processes waiting to read
  3. nw, number of processes writing and waiting to write
  4. i, index of current read folder, either 0 or 1.

The four operations, start reading, end reading, start writing, and end writing, are as follows:


start reading.

get the status memo
if nw=0
add one to nr
get a copy of the data memo from the read folder F[i]
replace the status memo
otherwise
add one to wtr
replace the status memo
get a copy of the data memo from the read folder F[1-i]

end reading
get the status memo
subtract one from nr
if nr=0 and nw>0,
get the data memo from the read folder F[i]
put it into the write folder
replace the status memo

start writing
get the status memo
add one to the nw
if nr=0 and nw=1
get the data memo from the read folder F[i]
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 nw=0
assign wtr to nr
assign 0 to wtr
i := 1 - i
replace the status memo
put the data memo into the read folder F[i]
otherwise nw>0
put the data memo into the write folder
replace the status memo

This page last updated 04/06/97