📜  门| GATE-CS-2016(套装1)|第 60 题

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

考虑以下针对临界区问题提出的解决方案。有 n 个进程:P0 …Pn-1。在代码中,函数pmax 返回一个不小于其任何参数的整数。对于所有 i,t[i] 被初始化为零。
僵局

关于上述解决方案,以下哪一项是正确的?
(A)任何时候至多一个进程处于临界区
(B)满足有界等待条件
(C)满足进度条件
(D)不会造成死锁答案:(一)
解释:

Mutual exclusion  is satisfied:
All other processes j started before i must have value (i.e. t[j]) 
less than the value of process i (i.e. t[i])  as function pMax() 
return a integer not smaller  than any of its arguments. So if anyone 
out of the processes j have positive value will be executing in its 
critical section as long as the condition t[j] > 0 && t[j] <= t[i] within 
while will persist. And when  this j process comes out of its critical 
section, it sets t[j] = 0;  and next process will be selected in for loop.
So when i process reaches to its critical section none of the  processes j 
which started earlier before process i  is in its critical section. This 
ensure that only one process is executing its critical section at a time. 
Deadlock and progress are  not satisfied:  
while (t[j] != 0 && t[j] <=t[i]); because of this condition deadlock is 
possible when value of j process becomes equals to the value of process i 
(i.e t[j] == t[i]).  because of the deadlock progess is also not possible 
(i.e. Progess == no deadlock) as no one process is able to make progress  
by stoping other process. 
Bounded waiting is also not satisfied: 
In this case both deadlock and bounded waiting to be arising from the same 
reason as if t[j] == t[i] is possible then starvation is possible means 
infinite waiting.

此解释由 Dheerendra Singh 提供。
这个问题的测验