📜  操作系统|流程管理|问题6

📅  最后修改于: 2021-06-29 17:22:24             🧑  作者: Mango

某个计算会生成两个数组a和b,使得0≤i

Process X:                         Process Y:
private i;                         private i;
for (i=0; i < n; i++) {            for (i=0; i < n; i++) {
   a[i] = f(i);                       EntryY(R, S);
   ExitX(R, S);                       b[i]=g(a[i]);
}                                 }

以下哪一项表示ExitX和EntryY的正确实现?

(一种)

ExitX(R, S) {
  P(R);
  V(S);
}

EntryY (R, S) {
  P(S);
  V(R);
}

(B)

ExitX(R, S) {
  V(R);
  V(S);
}

EntryY(R, S) {
  P(R);
  P(S);
}

(C)

ExitX(R, S) {
  P(S);
  V(R);
}
EntryY(R, S) {
  V(S);
  P(R);
}

(D)

ExitX(R, S) {
  V(R);
  P(S);
}
EntryY(R, S) {
  V(S);
  P(R);
}

(A) A
(B) B
(C) C
(D) D答案: (C)
解释:

The purpose here is neither the deadlock should occur
nor the binary semaphores be assigned value greater 
than one.
A leads to deadlock
B can increase value of semaphores b/w 1 to n
D may increase the value of semaphore R and S to
 2 in some cases

这个问题的测验