/// <summary> /// /// </summary> private void Initialize() { Parallel.For(1, 10000, (index, state) => { bag.Add(index * Math.Log(index)); var _singleton = Singleton.AllSingletons; _lazySingleton = LazySingleton <Singleton> .Instance; if (_singleton.GetHashCode() == _lazySingleton.GetHashCode()) { } }); }
/// <summary> /// /// </summary> private void Initialize() { Parallel.For(1, 10000, (index, state) => { bag.Add(index * Math.Log(index)); var _singleton= Singleton.AllSingletons; _lazySingleton= LazySingleton<Singleton>.Instance; if (_singleton.GetHashCode() == _lazySingleton.GetHashCode()) { } }); }
public void MultiThread() { LazySingleton instance1 = null; LazySingleton instance2 = null; Parallel.Invoke( () => { instance1 = LazySingleton.Instance; }, () => { instance2 = LazySingleton.Instance; } ); Assert.Multiple(() => { Assert.AreSame(instance1, instance2); Assert.AreEqual(instance1.GetHashCode(), instance2.GetHashCode()); Assert.AreEqual(1, LazySingleton.Counter, "There is more than 1 instance!"); }); }