C++0x对局部静态初始化作出了线程安全的要求,singleton的写法可以回归到最原始的方式
2013-08-19 17:39
225 查看
class Foo { public: staticFoo& instance(void) { static Foo s_instance; return s_instance; } }; 以下摘自ISOIEC 14882 C++11 6.7.4 The zero-initialization (8.5) of all block-scope variables with static storage duration (3.7.1) or thread storage duration (3.7.2) is performed before any other initialization takes place. Constant initialization (3.6.2) 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 (3.6.2). 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.88 If control re-enters the declaration recursively while the variable is being initialized, the behavior is undefined.
相关文章推荐
- C++ 局部静态初始化不是线程安全!
- C++ 局部静态初始化不是线程安全的!
- 只有静态常量整型数据成员才可以在类中初始化
- 全局变量,局部静态变量初始化以及类静态成员变量初始化
- Singleton - 用“静态初始化”在 .NET 中实现 Singleton & 多线程 Singleton
- 今天无意中发现JavaBean类基本都要求实现了Serializable接口,以前只是知道序列化以后,可以通过io流的方式将对象序列化和反序列化,进行存取,但不知道为什么需要序列化,今天总结一下
- static(c中定义的关键字1、被其修饰者 外部无法使用(相反的都可以使用extern在外部使用) 2、函数局部变量使用成为静态的放入静态池-生存期改变。c++进行了扩充,使它在类中有了特殊作用)
- 只有静态的常量整形数据成员才可以在类定义中初始化
- 值类型局部变量必须先初始化才能使用,值类型成员变量可以不初始化。
- c++中可以对类中私有成员中的静态变量初始化吗?
- 二维数组的定义(动态初始化、静态初始化)、初始化格式及其操作、java中的参数传递方式,面向对象的基本概念
- 长度为n的整数数组,找出其中任意(n-1)个乘积最大的那一组,只能用乘法,不可 以用除法。要求对算法的时间复杂度和空间复杂度作出分析,可以写思路也可以写程序。
- 静态页面也可以实现预览 列表不同的显示方式 原创
- 只有静态常量整型数据成员才可以在类中初始化
- 哪些方式实现可以线程安全
- 内存分配方式(动态/静态)的不同对const变量(全局/局部)访问性的影响
- 静态构造函数可以确定静态字段的初始化顺序及引用项目和引用该项目组件的区别
- c语言 全局(静态)和局部数组初始化
- 关于“只有静态常量整型数据成员才可以在类中初始化”
- c++中可以对类中私有成员中的静态变量初始化吗?