gpt4 book ai didi

c++ - 程序启动/不启动线程时的变量初始化

转载 作者:行者123 更新时间:2023-11-28 06:48:05 28 4
gpt4 key购买 nike

您能解释一下程序启动和不启动线程时变量初始化顺序的区别吗?

秒。 3.6.2/3 N3797 c++14 工作草案:

If a program starts a thread (30.3), the subsequent initialization of a variable is unsequenced with respect to the initialization of a variable defined in a different translation unit. Otherwise, the initialization of a variable is indeterminately sequenced with respect to the initialization of a variable defined in a different translation unit.

如果可能的话,请举例说明该规则。

最佳答案

Unsequenced 表示没有顺序 - 变量可以在不同线程上同时初始化。

不确定顺序 意味着一个顺序先于另一个 - 变量在同一线程上按顺序初始化 - 但未指定哪个先初始化。

关于c++ - 程序启动/不启动线程时的变量初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572870/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com