CS FundamentalsVery hardGATE CS (PYQ pattern)

Shared integer x = 1. Thread T1 executes x = x + 1; x = x + 1; and thread T2 executes x = x * 2;. Each statement is compiled to a LOAD into a private register followed by a STORE, with no locking, and the threads interleave arbitrarily at the instruction level. Which set is exactly the set of possible final values of x?

  1. A. {2, 3, 4, 5, 6}
  2. B. {4, 5, 6}
  3. C. {2, 3, 4, 6}
  4. D. {2, 3, 4, 5, 6, 8}

Correct answer: A. {2, 3, 4, 5, 6}

Enumerating all interleavings of the 4 + 2 instructions gives [2, 3, 4, 5, 6]. Atomic statements would give only 4, 5 or 6; lost updates add 2 and 3.

More Operating Systems questions

Exams that ask this topic