【发布时间】:2017-05-23 01:59:36
【问题描述】:
根据这个comment可以看到定义
void f() {
thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
等价于
void f() {
static thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
但我发现一些开源项目中使用了以下类似代码:
void f() {
static thread_local vector<int> V;
......
}
根据我的理解,在这里添加static应该是没有意义的。那么将static 用于thread_local 变量有什么好处吗?比如做一些编译优化?
【问题讨论】:
-
提高可读性?
标签: c++ static thread-local-storage