Reputation: 2050
In C++, do I have to worry about multiple threads operating on an object during static initialisation or is it guaranteed to be performed by a single thread?
Upvotes: 1
Views: 152
Reputation: 9393
One little caveat: do any of your global-scope static objects spawn threads from their constructors? If so, those threads will be running during static initialization time.
Upvotes: 0
Reputation: 258638
For global-scoped static
variables, yes.
For local static
s (declared inside functions), this guarantee only holds in C++11 and after.
Upvotes: 2