C# 编码的双重检验锁定

// Port to C#
class Singleton {
 public static Singleton Instance() {
   if (_instance == null)//提高效率
       {
   lock (typeof(Singleton)) {
    if (_instance == null) //防止多次创建单例对象
              {
     _instance = new Singleton();
    }
   }
  }
return _instance;
}
protected Singleton() {
}
private static volatile Singleton _instance = null;
}

posted on 2009-06-22 18:42  ATAK  阅读(856)  评论(1编辑  收藏  举报

导航