LearnFrenzy
Sign in Take a free test

Static and Friend Members · Static and Friend MCQ · Question 10

Is static local initialization thread-safe? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links