Is local static variable initialization thread-safe in C++11? [duplicate]

I know this is an often asked question, but as there are so many variants, I’d like to re-state it, and hopefully have an answer reflecting the current state. Something like

Logger& g_logger() {
    static Logger lg;
    return lg;
}

Is the constructor of variable lg guaranteed to run only once?

I know from previous answers that in C++03, this is not; in C++0x draft, this is enforced. But I’d like a clearer answer to

  1. In C++11 standard (not draft), is the thread-safe initialization behavior finalized?
  2. If the above is yes, in current latest releases of popular compilers, namely gcc 4.7, vc 2011 and clang 3.0, are they properly implemented?

2 Answers
2

Leave a Comment