读者写者问题,共享原则如下:1、读/写互斥访问;2、写/写互斥访问;3、允许多个读者同时对文件进行访问。
(2)写者优先
int readcount=0,writecount=0;
semaphore rmutex=1,wmutex=1,rwmutex=1,z=1,x=1;
reader writer
begin begin
repeat repeat
P(z); P(wmutex)
P(x); writecount:=writecount+1;
P(rmutex) if writecount=1 then P(x);
readcount:=readcount+1; V(wmutex)
if (readcount==1) P(rwmutex); P(rwmutex)
V(rmutex) writing;
V(x) V(rwmutex)
V(z) P(wmutex)
reading; writecount:=writecount-1;
P(rmutex) if writecount=0 then V(x);
readcount:=readcount-1; V(wmutex)
if (readcount==0) V(rwmutex); until false;
v(rmutex) end
until false;
end
在这里面的Z,X是什么的信号量啊???帮忙分析一下。。。不大看得懂