According to this comment, I can see the definition
void f() {
thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
is equivalent to
void f() {
static thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
But I have found the following like code is used in some Open Source projects:
void f() {
static thread_local vector<int> V;
......
}
Per my understanding, it should be meaningless to add static
here. So is there any benefit of using static
for thread_local
variables? Such as do some compiling optimizations?