/// <summary>
        /// The base method test run.
        /// </summary>
        public void Run()
        {
            Console.WriteLine($"Thread {this.Name} start instructions");
            Console.WriteLine($"Run with waiting **** Thread {this.Name} Loading: singleton, singletonWithLock\n");

            try
            {
                Task t1 = new Task(delegate()
                {
                    singleton = Singleton.Instance;
                    Console.Write($"singleton\n");
                    Thread.Sleep(3000);
                });
                Task t2 = t1.ContinueWith((t) =>
                {
                    singletonWithLock = SingletonWithLock.Instance;
                    Console.Write("singletonWithLock\n");
                    Thread.Sleep(3000);
                });

                t1.Start();
                t2.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Thread {this.Name} - error");
                throw e;
            }

            Console.WriteLine($"Thread {this.Name} - finish work.");
        }
Beispiel #2
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!");
        }
Beispiel #3
0
        public void ZadanieASingletonWithLockOneTask()
        {
            SingletonWithLock s = SingletonWithLock.GetSingleton();

            Assert.AreEqual(SingletonWithLock.constructorCount, 1, "Ilość Singletonów różna od 1!");
        }