Code Room
Code reviewHardcr-g007
Subject Lock misuseLevel Senior–Staff~28 minCommon in Concurrency interviewsIndustries Software development

Question

Review this C++ thread-safe queue.

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 reviewcpp
template <class T>class Queue {  std::mutex m_;  std::deque<T> q_;public:  void push(T v) {    m_.lock();    q_.push_back(std::move(v));    m_.unlock();  }  T pop() {    m_.lock();    T v = std::move(q_.front());    q_.pop_front();    return v;  }};
Run or narrate your approach, then ask the coach.