CS FundamentalsVery hardGATE CS

Shared x = 1. Thread A executes x = x + 1 twice; thread B executes x = x * 2 once; each statement is a separate load and store and there is no locking. Which set lists exactly the possible final values?

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

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

Serial-like orders give 6, 5 and 4. If B loads 1 and stores 2 after both of A's updates, the result is 2; if A's second update loads before B's store and writes last, it can be 3. So {2, 3, 4, 5, 6}.

More Operating Systems questions

Exams that ask this topic