Dean DeRosa
Dean DeRosa

Reputation: 61

Why is it forbidden to initialize a thread-local variable with a static constructor?

The ELF Handling For Thread document warns that when declaring a variable to have thread-local scope, "The only real limitation is that in C++ programs thread-local variables must not require a static constructor." I was on the understanding that C++ does not have static constructors because of the static initialization order fiasco.

So why does the document warn us against a feature that does not exist? Does the document really refer to constructors that behave like static constructors. For example one that refers to a potentially uninitialized static variable in its constructor?

More interestingly, let's say that a C++ static constructor did exist. What would be the problem with initializing a thread-local variable with a static constructor?

Upvotes: 0

Views: 25

Answers (0)

Related Questions