Пример #1
0
        public void Test_InMonitor_WithDoubleEntriesSingleTask_ExceptionInOuter()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

            for (int i = 0; i < numberOfIterations; i++)
            {
                try
                {
                    monitor.InMonitor(() =>
                    {
                        cnt++;

                        monitor.InMonitor(() =>
                        {
                            cnt++;
                        });

                        throw new ApplicationException();
                    });
                }
                catch (ApplicationException)
                {
                }
            }

            Assert.AreEqual(numberOfIterations * 2, cnt);
        }
Пример #2
0
        public void Test_InMonitor_WithDoubleEntriesMultipleTasks_ExceptionInOuter()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

            Parallel.For(0, numberOfIterations, i =>
            {
                try
                {
                    monitor.InMonitor(() =>
                    {
                        cnt++;

                        monitor.InMonitor(() =>
                        {
                            cnt++;
                        });

                        throw new ApplicationException();
                    });
                }
                catch (ApplicationException)
                {
                }
            });

            Assert.AreEqual(numberOfIterations * 2, cnt);
        }
Пример #3
0
        public void Test_InMonitor_WithDoubleEntriesMultipleTasks()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

            Parallel.For(0, numberOfIterations, i =>
                         monitor.InMonitor(() =>
            {
                cnt++;

                monitor.InMonitor(() =>
                {
                    cnt++;
                });
            }));

            Assert.AreEqual(numberOfIterations * 2, cnt);
        }
Пример #4
0
        public void Test_InMonitor_WithDoubleEntriesSingleTask()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

            for (int i = 0; i < numberOfIterations; i++)
            {
                monitor.InMonitor(() =>
                {
                    cnt++;

                    monitor.InMonitor(() =>
                    {
                        cnt++;
                    });
                });
            }

            Assert.AreEqual(numberOfIterations * 2, cnt);
        }