多个进程共享一个文件,其中只读文件的称为读者,其中只写文件的称为写者。读者可以同时读,但是写者只能独立地写。 用P、V操作写出其同步算法。

admin2013-03-18  21

问题 多个进程共享一个文件,其中只读文件的称为读者,其中只写文件的称为写者。读者可以同时读,但是写者只能独立地写。
用P、V操作写出其同步算法。

选项

答案用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

解析
转载请注明原文地址:https://kaotiyun.com/show/3Vsp777K
0

最新回复(0)