Open In App

GATE | GATE MOCK 2017 | Question 30

Consider the following C code for process P1 and P2. a=4, b=0, c=0 (initialization)

     P1                      P2
  if (a < 0)                b = 10;    
    c = b-a;                a = -3;
  else
    c = b+a;

If the processes P1 and P2 executes concurrently (shared variables a, b and c), which of the following cannot be the value of ‘c’ after both processes complete?



(A) 4
(B) 7
(C) 10
(D) 13

Answer: (C)
Explanation:

P1 : 1, 3, 4 -> c = 0+4 =4 {hence option a}
P2 : i, ii and P1 : 1, 2 -> c = 10-(-3) = 13 {hence option d}
P1 : 1 , P2 : i, ii and P1 : 3, 4 -> c= 10+(-3) = 7 { hence option b}
So 10 cannot be c value.

Quiz of this Question



Article Tags :