Пример #1
0
        public void ZadanieASingletonWithLockManyTasks()
        {
            Task[] tasks = new Task[100];
            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = new Task(() =>
                {
                    SingletonWithLock s = SingletonWithLock.GetSingleton();
                });
                tasks[i].Start();
            }

            tasks.AsParallel().ForAll(task => task.Wait());
            Assert.AreEqual(SingletonWithLock.constructorCount, 1, "Ilość Singletonów różna od 1!");
        }
Пример #2
0
        public void ZadanieALazySingletonManyTasks()
        {
            Task[] tasks = new Task[100];
            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = new Task(() =>
                {
                    LazySingleton s = LazySingleton.singleton;
                });
                tasks[i].Start();
            }

            tasks.AsParallel().ForAll(task => task.Wait());
            Assert.AreEqual(LazySingleton.constructorCount, 1, "Ilość Singletonów różna od 1!");
        }