Code Room
Code reviewHardcr-g411
Subject Concurrency bugsLevel Senior–Staff~32 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Java latch used by a coordinator to wait until a result is ready.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewjava
class ResultGate {  private final Object lock = new Object();  private boolean ready = false;  private Object value;   void publish(Object v) {    value = v;    synchronized (lock) { ready = true; lock.notify(); }  }   Object await() throws InterruptedException {    synchronized (lock) {      if (!ready) lock.wait();      return value;    }  }}
Run or narrate your approach, then ask the coach.