Given:
void getBlah() {
static Blah* blah = new Blah();
return blah;
}
In a multi threaded setting, is it possible that new Blah() is called more than once?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The C++ standard makes no guarantee about the thread safety of static initializations – you should treat the static initialization as requiring explicit synchronisation.
The quote Alexander Gessler gives:
is from the C++0x draft, and doesn’t reflect the current C++ standard or the behaviour of many C++ compilers.
In the current C++ standard, that passage reads: