21
Suppose there is a function (member function possibly)
SomeType foo()
{
static SomeType var = generateVar();
return var;
}
How var will be initialised if foo will be called 'for first time' from multiple threads simultaneously?
- Is it guaranteed that
generateVar()will be called only once in any scenario (if used of course)? - Is it guaranteed that
foowill return the same value when called multiple times in any scenario? - Is there a difference in behaviour for primitive or non-primitive types?