Пример #1
0
        public void testSingletonOneForProcess()
        {
            SingletonOneForProcess s1 = SingletonOneForProcess.Instance();
            SingletonOneForProcess s2 = SingletonOneForProcess.Instance();

            Assert.IsNotNull(s1);
            Assert.IsNotNull(s2);

            Assert.AreSame(s1, s2);
        }
Пример #2
0
 public static SingletonOneForProcess Instance()
 {
     if (instance == null)
     {
         lock (_lock) {
             if (instance == null)
             {
                 instance = new SingletonOneForProcess();
             }
         }
     }
     return(instance);
 }
Пример #3
0
        public void testSingletonOneForProcess_threads()
        {
            Thread t1, t2;
            SingletonOneForProcess s1 = null, s2 = null;

            t1 = new Thread(() => {
                s1 = SingletonOneForProcess.Instance();
            });

            t2 = new Thread(() => {
                s2 = SingletonOneForProcess.Instance();
            });

            t1.Start();
            t2.Start();
            t1.Join();
            t2.Join();

            Assert.IsNotNull(s1);
            Assert.IsNotNull(s2);

            Assert.AreSame(s1, s2);
        }