Code RoomLogger singleton publication
HardPrep Room Coding #2043

Logger singleton publication

Code reviewConcurrencySenior–Staff~30 min

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.

0:00 of about 30 min
Mark a line and say what kind of problem it is.0 findings
1static Logger* instance = nullptr;
2static std::mutex initMu;
3 
4Logger* getLogger() {
5 if (instance == nullptr) {
6 std::lock_guard<std::mutex> g(initMu);
7 if (instance == nullptr) {
8 instance = new Logger(); // construct then publish
9 }
10 }
11 return instance;
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.