线程局部变量的初始化顺序
initialization order of thread local variables
引用N4713:
使用静态动态初始化非局部变量 V 和 W 存储持续时间排序如下:
如果 V 和 W 已订购 初始化和 V 在单个转换中的 W 之前定义 单位,V的初始化在初始化之前排序 的W。
线程存储持续时间的变量是否有类似的段落?在下面的代码中,初始化之前V
是排序的W
?
thread_local int V = 1;
thread_local int W = V;
更新:
我想修改代码如下:
thread_local string V;
thread_local string W;
从6.7.2 线程存储持续时间 [basic.stc.thread]:
具有线程存储持续时间的变量应在首次使用 (6.2( 之前初始化,如果构造, 应在线程退出时销毁。
这意味着V
在"W"之前初始化。
相关文章:
- lambda 作为接受其他参数的参数的初始化顺序
- 大括号或等于初始值设定项初始化顺序
- 类内初始化与构造函数初始化列表的顺序
- C++ 模板中的静态常量初始化顺序
- 如果在 C++ 构造函数中以错误的顺序初始化对象数据,会发生什么类型的错误
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- 构造函数中没有参数的对象类成员按什么顺序初始化?
- 销毁 pthread 互斥体和 C++ 中的取消初始化顺序
- 线程局部变量的初始化顺序
- 初始化值是否保证通过其自己的地址反映,而不考虑内存顺序
- 类静态变量初始化顺序
- 具有静态存储持续时间的常量初始化变量的初始化顺序
- 解析 CRTP 初始化顺序
- 初始化相等C++的顺序
- 内联初始化的静态 const 类成员的初始化顺序保证
- 使用constexpr的全局初始化顺序
- 初始化与类类型相同的静态成员(静态初始化顺序问题)
- 结构化绑定的标识符是否按顺序初始化?
- c++中的求值顺序初始化数组
- c++标准和C语言在哪里说的是一样的:编译单元(.cpp文件)中的变量是按照声明的顺序初始化的