• 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.
  • 相关阅读:
    c# CLR无法从 COM 上下文 0x51cd20 转换为 COM 上下文 0x51ce90
    sql语法
    学籍管理系统
    【Android进阶】Android调用WebService的实现
    【Android进阶】自定义控件实现底部扇形展开菜单效果
    华为上机题汇总----java
    卡片游戏(栈和队列)
    18岁生日
    循环多少次?
    Flappy bird源代码(略吊)
  • 原文地址:https://www.cnblogs.com/rickerliang/p/3268343.html
Copyright © 2020-2023  润新知