📜  门| GATE CS 1997 |第72章

📅  最后修改于: 2021-06-29 22:44:54             🧑  作者: 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的伪代码。回答:
解释:
这个问题的测验