zoukankan      html  css  js  c++  java
  • C++0x对局部静态初始化作出了线程安全的要求,singleton的写法可以回归到最原始的方式

    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.
  • 相关阅读:
    Linux上传下载文件(rz/sz)
    注册页面(函数调用,数组,对象,for,innerHTML)
    课程表(点击事件,for)
    winform中固定界面大小的方法
    VS常用快捷键
    Python的标准输出
    Spring注解驱动第二讲--@ComponentScan扫描介绍
    Spring注解驱动第一讲--Spring环境搭建
    通用目标检测
    通用目标检测-发展趋势
  • 原文地址:https://www.cnblogs.com/rickerliang/p/3268343.html
Copyright © 2011-2022 走看看