设为首页 加入收藏

TOP

C++ Singleton + MultiThread
2015-07-20 17:26:20 来源: 作者: 【 】 浏览:3
Tags:Singleton MultiThread
#include 
  
   
#include 
   
     using namespace std; template 
    
      class Singleton { public: static T *instance() { if (object == NULL) { mtx.lock(); if (object == NULL) object = new T; mtx.unlock(); } return object; } private: Singleton() {} // be here? necessary? static T *object; static mutex mtx; }; template 
     
       T* Singleton
      
       ::object = NULL; template 
       
         mutex Singleton
        
         ::mtx; class Foo { }; int main() { Foo *singletonFoo = Singleton
         
          ::instance(); return 0; }
         
        
       
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 10529 Dumb Bones 概率dp 求.. 下一篇HDOJ 4252 A Famous City 单调栈

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)