public void TestMethod2() { SingletonThread s1, s2; s1 = null; s2 = null; Thread t1, t2; t1 = new Thread(() => { s1 = SingletonThread.getInstance(); }); t2 = new Thread(() => { s2 = SingletonThread.getInstance(); }); t1.Start(); t2.Start(); t1.Join(); t2.Join(); Assert.AreNotSame(s1, s2); Assert.IsNotNull(s1); Assert.IsNotNull(s2); }
public static SingletonThread Instance() { if (_instance == null) { _instance = new SingletonThread(); } return(_instance); }
public void TestSameInstancesPerThread() { SingletonThread s = SingletonThread.Instance(); object s1 = null; object s2 = null; var thr1 = new Thread(() => { s1 = SingletonThread.Instance(); }); thr1.Start(); thr1.Join(); var thr2 = new Thread(() => { s2 = SingletonThread.Instance(); }); thr2.Start(); thr2.Join(); Assert.AreNotSame(s, s1); Assert.AreNotSame(s, s2); Assert.AreNotSame(s1, s2); }
public void TestSameInstances() { Assert.AreSame(SingletonThread.Instance(), SingletonThread.Instance()); }