Code Room
Code reviewHardcr-g588
Subject Concurrency thread unsafe lazy cppLevel Senior–Staff~29 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

Review this C++ thread-pool logger using a lazily created singleton.

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
class Logger {public:    static Logger* get() {        if (!instance) {            instance = new Logger();            instance->open("/var/log/app.log");        }        return instance;    }    void write(const std::string& s) { out << s << "\n"; }private:    static Logger* instance;    std::ofstream out;    void open(const char* p) { out.open(p, std::ios::app); }};Logger* Logger::instance = nullptr;
Run or narrate your approach, then ask the coach.