CS FundamentalsVery hardGATE CS (PYQ pattern)

Three threads each execute x = x + 1; twice on a shared int x that starts at 0 (so six increments in all). Each increment is a separate LOAD and STORE with no locking, and the threads may interleave arbitrarily. What are the minimum and maximum possible final values of x?

  1. A. 3 and 6
  2. B. 2 and 5
  3. C. 2 and 6
  4. D. 1 and 6

Correct answer: C. 2 and 6

Maximum 6 when no increments overlap. Exhaustive enumeration of all interleavings gives every value from 2 to 6; 1 is impossible because the last STORE overall is some thread's second store, which writes a value that is at least 2 (it follows that thread's own first store).

More Operating Systems questions

Exams that ask this topic