Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public void Test_InMonitor_WithMultipleTasks()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

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

            Assert.AreEqual(numberOfIterations, cnt);
        }
Ejemplo n.º 4
0
        public void Test_InMonitor_WithSingleTask()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

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

            Assert.AreEqual(numberOfIterations, cnt);
        }
Ejemplo n.º 5
0
        public void Test_EnterExit_WithMultipleTasks()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

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

            Assert.AreEqual(numberOfIterations, cnt);
        }
Ejemplo n.º 6
0
        public void Test_EnterExit_WithSingleTask()
        {
            const int numberOfIterations = 200;
            int       cnt     = 0;
            var       monitor = new SpinMonitor();

            for (int i = 0; i < numberOfIterations; i++)
            {
                monitor.Enter();
                cnt++;
                monitor.Exit();
            }

            Assert.AreEqual(numberOfIterations, cnt);
        }