Consider two processes P₁ and P₂ accessing the shared variables X and Y…

GATE · 2004 · CS

Consider two processes P₁ and P₂ accessing the shared variables X and Y protected by two binary semaphores Sₓ and Sᵧ respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P₁ and P₂ is as follows:

P₁:
while true do {
  L₁: ......
  L₂: ......
  X = X + 1;
  Y = Y - 1;
  V(Sₓ);
  V(Sᵧ);
}
P₂:
while true do {
  L₃: ......
  L₄: ......
  Y = Y + 1;
  X = X - 1;
  V(Sᵧ);
  V(Sₓ);
}

In order to avoid deadlock, the correct operators at L₁, L₂, L₃ and L₄ are respectively.

  1. A.

    P(SY), P(SX); P(SX), P(SY)

  2. B.

    P(SX), P(SY); P(SY), P(SX)

  3. C.

    P(SX), P(SX); P(SY), P(SY)

  4. D.

    P(SX), P(SY); P(SX), P(SY)

Attempted by 17 students.

Show answer

Correct answer: D

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

Loading lesson…