Beispiel #1
0
        public void ThreadSafeDoubleCheckLocking()
        {
            Double_CheckLocking.Singleton instance1 = Double_CheckLocking.Singleton.Instance();
            Double_CheckLocking.Singleton instance2 = Double_CheckLocking.Singleton.Instance();

            Assert.IsNotNull(instance1);
            Assert.IsNotNull(instance2);
            Assert.AreEqual(instance1, instance2);
        }
Beispiel #2
0
        public static Singleton Instance()
        {
            if(_instance == null)
            {
                lock (syncRoot)
                {
                    if (_instance == null)
                    {
                        _instance = new Singleton();
                    }
                }
            }

            return _instance;
        }