コード例 #1
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);
        }
コード例 #2
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);
        }