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.
(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}.)
The four operations, start reading, end reading, start writing, and end writing, are as follows:
start reading.
get the status memoif nw=0add one to nrget a copy of the data memo from the read folder F[i]replace the status memootherwiseadd one to wtrreplace the status memoget a copy of the data memo from the read folder F[1-i]
end reading
get the status memosubtract one from nrif nr=0 and nw>0,get the data memo from the read folder F[i]put it into the write folderreplace the status memo
start writing
get the status memoadd one to the nwif nr=0 and nw=1get the data memo from the read folder F[i]replace the status memootherwisereplace the status memoget the data memo from the write folder
end writing
get the status memosubtract one from nwif nw=0assign wtr to nrassign 0 to wtri := 1 - ireplace the status memoput the data memo into the read folder F[i]otherwise nw>0put the data memo into the write folderreplace the status memo
This page last updated 04/06/97