19 Apr
2012
19 Apr
'12
9:28 a.m.
Hi, <skip>
That depends on your compiler. In case 1, the mutex is constructed when "create_something" is first called. With gcc there is a command-line option (-fthreadsafe-statics) which ensures that this is done in a thread-safe manner, so you don't have 2 threads thinking they are "first". On many builds this is enabled by default, but the user can still disable it. I don't think MSVC has thread-safe statics before VC11, but I'm not sure. I don't know about other compilers.
In case 2, if you call create_something() after main() has started then it should be fine, as the class static will be fully constructed before main.
Thanks alot. -- The fish that is singing in Ucayali river...