czh306

导航

<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

统计

常用链接

留言簿(2)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜

C++/CLI中单件模板的实现

template<typename _T> public ref class Singleton : public _T
  {
  public:
   static _T^ Instance(void)
   {
    if (_instance == nullptr)
    {
     _mut->WaitOne();
     try
     {
      if (_instance == nullptr)
      {
       _instance = safe_cast<_T^>(gcnew Singleton<_T>);
      }
     }
     finally
     {
      _mut->ReleaseMutex();
     }
    }
    return _instance;
   }
  protected:
   Singleton(void){}
  protected:
   static _T^ _instance = nullptr;
   static System::Threading::Mutex^ _mut = gcnew System::Threading::Mutex();
  };

posted on 2006-07-18 16:01 czh306 阅读(370) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理