Exemplo n.º 1
0
        public void ShouldHandleManagedThreads()
        {
            var counter = 0;
            var a       = (Action)(() => counter++);

            using (var emulation = new Emulation())
            {
                var machine = new Machine();
                emulation.AddMachine(machine);

                emulation.SetGlobalQuantum(Time.TimeInterval.FromMilliseconds(1000));
                emulation.SetGlobalAdvanceImmediately(true);

                var mt = machine.ObtainManagedThread(a, 1);

                emulation.RunToNearestSyncPoint();
                emulation.RunToNearestSyncPoint();
                emulation.RunToNearestSyncPoint();
                Assert.AreEqual(0, counter);

                mt.Start();

                emulation.RunToNearestSyncPoint();
                Assert.AreEqual(1, counter);

                emulation.RunToNearestSyncPoint();
                Assert.AreEqual(2, counter);

                emulation.RunToNearestSyncPoint();
                Assert.AreEqual(3, counter);

                mt.Stop();

                emulation.RunToNearestSyncPoint();
                emulation.RunToNearestSyncPoint();
                emulation.RunToNearestSyncPoint();
                Assert.AreEqual(3, counter);
            }
        }