📜  门|门 CS 1997 |第 72 题

📅  最后修改于: 2021-09-26 04:24:00             🧑  作者: Mango

一个并发系统由 3 个进程组成,它们以不可抢占和互斥的方式使用共享资源 R。这些进程在 1…..3 范围内具有唯一的优先级,3 是最高优先级。需要同步进程,以便资源始终分配给最高优先级的请求者。系统伪代码如下。

Shared Data
mutex:semaphore = 1:/* initialized to 1*/
process[3]:semaphore = 0; /*all initialized to 0 */
R_requested [3]:boolean = false; /*all initialized to false */
busy: boolean = false; /*initialized to false */
Code for processes
begin process
my-priority:integer;
my-priority:=____; /*in the range 1...3*/
repeat
    request_R(my-priority);
    P (proceed [my-priority]);
    {use shared resource R}
    release_R (my-priority);
forever
end process;
Procedures
procedure request_R(priority);
P(mutex);
if busy = true then
    R_requested [priority]:=true;
else
 begin
    V(proceed [priority]);
    busy:=true;
 end
V(mutex);

给出过程 release_R的伪代码。回答:
解释:
这个问题的测验