GATE CS 2013 · Question 39 · Operating System · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

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:
private i; for (i=0; i<n; i++) { a[i] = f(i); ExitX(R, S); }
Process Y:
private i; for (i=0; i<n; i++) { EntryY(R, S); b[i] = g(a[i]); }
Which one of the following represents the CORRECT implementations of ExitX and EntryY?

  1. (A) ExitX(R, S) { P(R); V(S); } EntryY(R, S) { P(S); V(R); }
  2. (B) ExitX(R, S) { V(R); V(S); } EntryY(R, S) { P(R); P(S); }
  3. (C) ExitX(R, S) { P(S); V(R); } EntryY(R, S) { V(S); P(R); }
  4. (D) ExitX(R, S) { V(R); P(S); } EntryY(R, S) { V(S); P(R); }
Answer

Answer (C)

Answer from the official GATE CS 2013 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes