Code RoomSpurious wakeup unhandled
HardPrep Room Coding #1647

Spurious wakeup unhandled

Code reviewConcurrencySenior–Staff~30 min

Review this C++ bounded-buffer consumer wait.

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 30 min
Mark a line and say what kind of problem it is.0 findings
1std::mutex m;
2std::condition_variable cv;
3std::queue<Task> q;
4 
5Task take() {
6 std::unique_lock<std::mutex> lk(m);
7 if (q.empty()) {
8 cv.wait(lk);
9 }
10 Task t = std::move(q.front());
11 q.pop();
12 return t;
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.