Exemplo n.º 1
0
        public void OnlyOneInstanceExists_MultiplePararellThreads()
        {
            AnotherSingleton a = null;
            AnotherSingleton b = null;

            Parallel.Invoke(
                () => { a = AnotherSingleton.Instance; },
                () => { b = AnotherSingleton.Instance; }
                );

            Assert.AreEqual(1, AnotherSingleton.Counter);
        }
Exemplo n.º 2
0
        public void InstancePropertyReturnsSameInstance_MultiplePararellThreads()
        {
            AnotherSingleton a = null;
            AnotherSingleton b = null;

            Parallel.Invoke(
                () => { a = AnotherAnotherSingleton.Instance; },
                () => { b = AnotherSingleton.Instance; }
                );

            Assert.AreSame(b, AnotherAnotherSingleton.Instance);
        }