readers and writers: monitor
begin readercount : integer;
busy: Boolean;
OKtoread, OKtowrite:condition;
procedure startread;
begin
if busy V OKtowrite.queue then OKtoread.wait;
readercount := readercount + 1;
OKtoread.signal;
// Quando un lettore può iniziare, tutti possono
end startread;
procedure endread;
begin
readercount := readercount -- 1 ;
if readercount = 0 then OKtowrite.signal
end endread;
procedure startwrite;
begin
if readercount != 0 V busy then OKtowrite.wait
busy := true
end startwrite;
procedure endwrite;
begin
busy := false;
if OKtoread.queue then OKtoread.signal
else OKtowrite.signal
end endwrite;
readercount := 0;
busy := false;
end readers and writers;
Lorenzo Viola