Queue pop crashes on empty
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.
0:00 of about 28 min
Mark a line and say what kind of problem it is.0 findings
1template <class T>
2class Queue {
3 std::mutex m_;
4 std::deque<T> q_;
5public:
6 void push(T v) {
7 m_.lock();
8 q_.push_back(std::move(v));
9 m_.unlock();
10 }
11 T pop() {
12 m_.lock();
13 T v = std::move(q_.front());
14 q_.pop_front();
15 return v;
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.