All Questions
Dealing With Contention hard

Why must `wait()` always be called inside a `while(condition)` loop, not an `if(condition)` block?

  1. A It is syntax style.
  2. B Java requires it.
  3. C To save CPU.
  4. D To prevent Spurious Wakeups (the OS waking a thread without a signal) or the condition becoming false between wake-up and lock re-acquisition.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions