当前位置:首页 > 进程管理习题及答案
for i=1 to N P(out);
收齐卷子,离开考场 }
4、安全状态 P1-> P3-> P4-> P0-> P2 (答案不唯一)
5、P、V操作实现
程序如下:
student:=0; computer:=2m; enter:=0; finish:=0; test(i):=0; parbegin
Student i: Begin
V(student); /*表示有学生到达,通知gateguard进程 */ P(enter); /*学生是否可进入*/ 上机实习;
V(finish); /*实习结束,通知教师,有需要检查的学生*/ P(test(i)); /*等待教师检查完毕*/ V(computer); /*释放计算机资源} End; .
Teacher:Begin repeat
P(finish); /*是否有需要检查的学生,等待实习完成*/ P(finish); /*是否有需要检查的学生,等待实习完成*/ 选出可检查的第i组学生;
检查第i组学生实习结果;
V(test(i)); /*检查完成*/ V(test(i)); /*检查完成*/ until false End;
Gategard:Begin repeat.
P(student); /*等待学生到达*/
P(student); /*等待另一学生到达*/ P(computer); /*是否有可用的计算机*/ P(computer); /*是否有可用的计算机*/ 分配计算机;
V(enter); /*设置学生1可进入标志*/ V(enter); /*设置学生2可进入标志*/ untile false End; Parend;
共分享92篇相关文档