Code Room
Code reviewMedium
Question
Review this C++ worker-pool counter.
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.
Learn the concepts
#include <thread>#include <vector>#include <iostream> long counter = 0; void work(int iters) { for (int i = 0; i < iters; ++i) counter++;} int main() { std::vector<std::thread> ts; for (int t = 0; t < 8; ++t) ts.emplace_back(work, 1000000); for (auto& th : ts) th.join(); std::cout << counter << "\n"; // expect 8000000 return 0;}Run or narrate your approach, then ask the coach.