CS FundamentalsVery hardGATE CS

Shared x = 0. Thread A executes `x = x + 1;` twice and thread B executes `x = x - 1;` twice, with no synchronisation (each statement is load, compute, store). What are the minimum and maximum possible final values of x?

  1. A. −2 and 2
  2. B. 0 and 0
  3. C. −1 and 1
  4. D. −4 and 4

Correct answer: A. −2 and 2

Lost updates let one thread's effects vanish entirely: if B's final store overwrites everything A did, x can end at −2, and symmetrically at +2. Every value from −2 to 2 is reachable (verified by enumerating all interleavings).

More Operating Systems questions

Exams that ask this topic