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操作笔记
    TreeView获取目录下的所有文件
    treeList获取目录下的所有文件
    简单字符串处理 hdu2532 Engine
    简单字符串处理
    Luogu P1648 看守
    【深入理解Linux内核架构】第3章:内存管理
    【深入理解Linux内核架构】6.6 资源分配
    题解 P1888 【三角函数】
  • 原文地址:https://www.cnblogs.com/rickerliang/p/3268343.html
Copyright © 2011-2022 走看看