用PV操作解决读者写者问题的正确程序如下:beginS,Sr:Semaphore;rc:integer;S:=1;Sr:=1;rc:=0;cobeginPROCESReaderi(i=1,2…)beginP(Sr)rc:=rc+1;ifrc=1thenP(S);V(Sr);readfile;P(Sr);rc:=rc-1ifrc=0thenV(S);V(Sr);end;PROCESWriterj(j=1,2…)beginP(S);Writefile;V(S)end;coend;end;请回答:(1)信号量S


用PV操作解决读者写者问题的正确程序如下:beginS,Sr:Semaphore;rc:integer;S:=1;Sr:=1;rc:=0;cobeginPROCESReaderi(i=1,2…)beginP(Sr)rc:=rc+1;ifrc=1thenP(S);V(Sr);readfile;P(Sr);rc:=rc-1ifrc=0thenV(S);V(Sr);end;PROCESWriterj(j=1,2…)beginP(S);Writefile;V(S)end;coend;end;请回答:(1)信号量Sr的作用;(2)程序中什么语句用于读写互斥,写写互斥;(3)若规定仅允许5个进程同时读怎样修改程序?

正确答案:互斥|S5


Tag:计算机科学与技术操作系统 程序 信号量 时间:2024-01-22 10:45:42