You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
《C++ Concurrency in Action》Second Edition,Chapter 3.3.1 节最后部分关于 static变量 初始化的描述,仅指的是 static local variable 的初始化自 C++11 起是线程安全的,对于 static non-local variable 是未提及的,即对于具有静态存储期的非局部变量,如 global variable 和类的 static data member ,它们的初始化会作为程序启动的一部分在 main 函数的执行之前进行:简单的类型会在编译期进行初始化,如 constexpr 类型,复杂的类型则需要在运行期初始化,如 复杂的类对象(初始化时需要调用构造函数)。在程序结束时它们才会被销毁。因为 static non-local variable 的初始化会作为程序启动的一部分在 main 函数的执行之前进行,所以其初始化不存在多个线程竞争初始化的问题,但是却存在异常安全和 initialization order 的问题。详见 Static local variable and Global variable 。
即文中应该写为: “C++11规定static局部变量的初始化……”
Issue2
class A 的 copy assignment operator 漏写了字符 = ,即应该是: A& operator=(const A&) = delete;
The text was updated successfully, but these errors were encountered:
The zero-initialization of all block-scope variables with static storage duration or thread storage duration is performed before any other initialization takes place. Constant initialization of a block-scope entity with static storage duration, if applicable, is performed before its block is first entered. An implementation is permitted to perform early initialization of other block-scope variables with static or thread storage duration under the same conditions that an implementation is permitted to statically initialize a variable with static or thread storage duration in namespace scope. Otherwise such a variable is initialized the first time control passes through its declaration; such a variable is considered initialized upon the completion of its initialization. If the initialization exits by throwing an exception, the initialization is not complete, so it will be tried again the next time control enters the declaration. If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization. If control re-enters the declaration recursively while the variable is being initialized, the behavior is undefined.
Dynamic initialization of a block-scope variable with static storage duration or thread storage duration is performed the first time control passes through its declaration; such a variable is considered initialized upon the completion of its initialization. If the initialization exits by throwing an exception, the initialization is not complete, so it will be tried again the next time control enters the declaration. If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization. If control re-enters the declaration recursively while the variable is being initialized, the behavior is undefined.
文件位置: content/02 线程间共享数据.md
https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/cbd88caed525fffb736b4fe2fd3aa61a2d1f3bb2/content/02%20%E7%BA%BF%E7%A8%8B%E9%97%B4%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE.md
Issue1
《C++ Concurrency in Action》Second Edition,Chapter 3.3.1 节最后部分关于 static变量 初始化的描述,仅指的是 static local variable 的初始化自 C++11 起是线程安全的,对于 static non-local variable 是未提及的,即对于具有静态存储期的非局部变量,如 global variable 和类的 static data member ,它们的初始化会作为程序启动的一部分在 main 函数的执行之前进行:简单的类型会在编译期进行初始化,如
constexpr
类型,复杂的类型则需要在运行期初始化,如 复杂的类对象(初始化时需要调用构造函数)。在程序结束时它们才会被销毁。因为 static non-local variable 的初始化会作为程序启动的一部分在 main 函数的执行之前进行,所以其初始化不存在多个线程竞争初始化的问题,但是却存在异常安全和 initialization order 的问题。详见 Static local variable and Global variable 。即文中应该写为: “C++11规定static局部变量的初始化……”
Issue2
class A 的 copy assignment operator 漏写了字符
=
,即应该是:A& operator=(const A&) = delete;
The text was updated successfully, but these errors were encountered: