Open In App
Related Articles

Operating Systems | Process Management | Question 6

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and b[i]=g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.
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]);
}                                 }
Which one of the following represents the CORRECT implementations of ExitX and EntryY? (A)
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

Answer: (C)

Explanation:
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


Quiz of this Question

Last Updated : 28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads