on Fri Apr 20 2012, Will Mason
Hello,
On Fri, Apr 20, 2012 at 8:04 AM, Juan RamÃrez
wrote: It's not related to the user type, neither to mutex initialization, it's related to variable initialization in general.
A global static variable is guaranteed to be initialized before usage.
If you truly mean "static," such that it's not visible outside its translation unit, that is correct.
But the initialization of static variables declared inside a function is not guaranteed to be thread safe. So you could easily end up calling it's constructor twice.
That's something that boost::call_once is good at preventing.
Correct, for C++03. I could be mis-remembering but IIRC in C++11 function-local static variables have been given automatic threadsafe initialization. -- Dave Abrahams BoostPro Computing http://www.boostpro.com