Code Room
Code reviewHardcr-g415
Subject Double checked lockingLevel Senior–Staff~30 minCommon in Concurrency interviewsIndustries Software development

Question

Review this C++ lazy singleton meant to be thread-safe.

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
static Logger* instance = nullptr;static std::mutex initMu; Logger* getLogger() {  if (instance == nullptr) {    std::lock_guard<std::mutex> g(initMu);    if (instance == nullptr) {      instance = new Logger();   // construct then publish    }  }  return instance;}
Run or narrate your approach, then ask the coach.