CS FundamentalsVery hardGATE CS

Shared x = 1. Three threads run once each, with no locking: T1 does x = x + 2, T2 does x = x * 3, T3 does x = x − 1. Each statement is a separate load then store. How many distinct final values of x are possible?

  1. A. 6
  2. B. 8
  3. C. 4
  4. D. 9

Correct answer: B. 8

The 6 serial orders give 8, 6, 4, 2 (two orders give 4 and two give 6), and lost updates add 0, 3, 5 and 9, e.g. T1 and T2 serially (9) with T3's stale write lost. Enumerating all load/store interleavings gives {0, 2, 3, 4, 5, 6, 8, 9}: 8 values.

More Operating Systems questions

Exams that ask this topic