🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Semaphores and Classic Problems: all 9 questions

Quiz: Semaphores and Classic Problems · Question 3 of 9

Two threads each run x = x + 1 once on shared x = 0, with no lock. Which final values are possible?

Two threads each run x = x + 1 once on shared x = 0, with no lock. Which final values are possible?

  1. A.Only 2
  2. B.0, 1 or 2
  3. C.1 or 2
  4. D.Only 1
Answer & explanation

Correct answer: 1 or 2

If both load 0 before either stores, one update is lost and x is 1.

Can you get the rest right without peeking?

Take the timed Quiz: Semaphores and Classic Problems quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →