Question 10
Back to Exercise
Since C++11, what happens if two threads call a function containing static Logger log; for the first time at the same moment?
- A log may be constructed twice
- B The initialization is guaranteed to happen exactly once; the other thread waits Correct
- C The program crashes
- D Undefined behaviour
Correct Answer: Option B
"Magic statics" make the Meyers singleton thread-safe without explicit locking.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!