Result gate reads stale value
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.
0:00 of about 32 min
Mark a line and say what kind of problem it is.0 findings
1class ResultGate {
2 private final Object lock = new Object();
3 private boolean ready = false;
4 private Object value;
5
6 void publish(Object v) {
7 value = v;
8 synchronized (lock) { ready = true; lock.notify(); }
9 }
10
11 Object await() throws InterruptedException {
12 synchronized (lock) {
13 if (!ready) lock.wait();
14 return value;
15 }
16 }
17}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.