The rules of the taking-turns shared record are these:
A solution to this problem in Memo uses the same four folders, extra status record, and data record as are used in the writers-preferred solution.
(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](the other read folder)
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 number of writersif 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 wtr>0 or nw=0assign wtr to nrassign 0 to wtri := 1 - ireplace the status memoput the data memo into the read folder F[i]otherwise wtr=0 or nw>0put the data memo into the write folderreplace the status memo
This page last updated 09/30/97