Exemplo n.º 1
0
        public void MicroThreadTest()
        {
            MicroThread microA = new MicroThread();
            MicroThread microB = new MicroThread();

            microA.MainThread.Mark();
            microA.MyThread.Mark();
            microB.MainThread.Mark();
            microB.MyThread.Mark();

            Assert.AreEqual(false, microA.Done);
            Assert.AreEqual(false, microB.Done);

            microA.DoWork(() =>
            {
                int count = 0;
                while (count < 100)
                {
                    ++count;
                    if (count % 10 == 0)
                    {
                        microA.Yield();
                    }
                }
            });

            MicroBJob jobB = new MicroBJob();

            jobB.MicroThread = microB;

            microB.DoWork(jobB.Work);

            Assert.AreEqual(false, microA.Done);
            Assert.AreEqual(false, microB.Done);

            int yields = 0;

            while (yields < 20)
            {
                if (!microA.Done)
                {
                    microA.Resume();
                }
                if (!microB.Done)
                {
                    microB.Resume();
                }
                if (microA.Done && microB.Done)
                {
                    break;
                }
                ++yields;
            }

            Assert.AreEqual(true, microA.Done);
            Assert.AreEqual(true, microB.Done);
            Assert.AreEqual(100, jobB.Count);
            Assert.AreEqual(9, yields);
        }
Exemplo n.º 2
0
 public void Work()
 {
     while (Count < 100)
     {
         ++Count;
         if (Count % 10 == 0)
         {
             MicroThread.Yield();
         }
     }
 }
Exemplo n.º 3
0
        public void MicroThreadTest()
        {
            MicroThread microA = new MicroThread();
            MicroThread microB = new MicroThread();

            microA.MainThread.Mark();
            microA.MyThread.Mark();
            microB.MainThread.Mark();
            microB.MyThread.Mark();

            Assert.AreEqual(false, microA.Done);
            Assert.AreEqual(false, microB.Done);

            microA.DoWork(() =>
            {
                int count = 0;
                while (count < 100) {
                    ++count;
                    if (count % 10 == 0) {
                        microA.Yield();
                    }
                }
            });

            MicroBJob jobB = new MicroBJob();
            jobB.MicroThread = microB;

            microB.DoWork(jobB.Work);

            Assert.AreEqual(false, microA.Done);
            Assert.AreEqual(false, microB.Done);

            int yields = 0;
            while (yields < 20) {
                if (!microA.Done) microA.Resume();
                if (!microB.Done) microB.Resume();
                if (microA.Done && microB.Done) break;
                ++yields;
            }

            Assert.AreEqual(true, microA.Done);
            Assert.AreEqual(true, microB.Done);
            Assert.AreEqual(100, jobB.Count);
            Assert.AreEqual(9, yields);
        }