A certain computation generates two arrays a and b such that a[i] = f(i) for 0…
GATE · 2013 · CS · Computer Science & ITBARC · Computer Science · 2013
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: X computes array a, and Y computes array b. The processes use two binary semaphores R and S, both initialized to zero. Array a is shared by the two processes.
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?
- 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); }
Attempted by 251 students.
Show answer
Correct answer: C
The worked solution is available to enrolled students.
Video solution available to enrolled students.
Explore the full course: Iocl Engineers Officers Grade A Paper 2