I am trying to understand the behavior of local statics with gcc and c++ (pre c++11 and post). A lot of times, in a member function I find myself doing something like so:
struct Foo
{
void foo()
{
static const bool bar = someFunc();
//etc
}
};
For example where someFunc() is getenv("SOME_ENV_VAR"). In the above code, what are the rules governing bar? I believe, but do not have a reference, that gcc will compile a synchronization mechanism (not sure what) to protect the above local static from multiple threads. How do things change if it is no longer const? or if we make it thread local with __thread? And if foo() is not a member function?