CS FundamentalsModerateGATE CS

Shared x = 0. Three threads each execute `x = x + 1;` once (load, add, store; no locking). What is the set of possible final values?

  1. A. {3}
  2. B. {0, 1, 2, 3}
  3. C. {2, 3}
  4. D. {1, 2, 3}

Correct answer: D. {1, 2, 3}

Each thread's store writes (value it loaded) + 1. If all three load 0 before any store, the result is 1; serial execution gives 3; partial overlap gives 2. 0 is impossible since every thread stores at least 1.

More Operating Systems questions

Exams that ask this topic