The distinction exists in C/C++ prior to C++ 11 and in C++ 11 or later (Earlier standards lacked any provisions for threading.).
As you can see here: C++ Static local variables, since C++11 is it guaranteed by the standard that a static local variable will be initialized only once. There is a specific note regarding locks that can be applied to ensure single initializing in a multi threaded environment:
If multiple threads attempt to initialize the same static local
variable concurrently, the initialization occurs exactly once (similar
behavior can be obtained for arbitrary functions with std::call_once).
Note: usual implementations of this feature use variants of the
double-checked locking pattern, which reduces runtime overhead for
already-initialized local statics to a single non-atomic boolean
comparison.
The rules in C are specified here: C Storage duration:
static storage duration. The storage duration is the entire execution
of the program, and the value stored in the object is initialized only
once, prior to main function. All objects declared static and all
objects with either internal or external linkage that aren't declared
_Thread_local (since C11) have this storage duration.
t
is thread safe since C++11. Before C++11, it was not thread safe (since earlier standards didn't have any provision related to threading at all). I believe the initialisation oft
is also thread safe in C, mostly because static variables can only be initialised with literals (compile time constants) in C [from which I infer that the structure will be initialised before any thread ever accesses it]. – Vengeancemalloc
? – Succorconstexpr
keyword giving some more options (not to be confused with C++). Also some non-conforming compilers like gcc accept a few more options. – Skink