【答案解析】用P、V操作的同步算法如下:
Begin
Integer mutex1,mutex2,rc;
mutex1:=1;
mutex2:=1;
rc:=0;
Cobegin
Reader;
Begin
P(mutex1);
rc:=rc+1;
if rc_1 then p(mutex2);
V(mutex1);
Reading the file;
rc:=rc-1;
if rc=0 then V(mutex2);
V(mutex1);
End
Writer:
Begin
p(mutex2);
Writing the file;
V(mutex2);
End
Coend
End