示例#1
0
        public void Test1Test()
        {
            var Values = new List <int>();

            var Thread1 = new GreenThread();
            var Thread2 = new GreenThread();

            Thread1.InitAndStartStopped(() =>
            {
                Values.Add(1);
                GreenThread.Yield();
                Values.Add(3);
            });
            Thread2.InitAndStartStopped(() =>
            {
                Values.Add(2);
                GreenThread.Yield();
                Values.Add(4);
            });

            Thread.Sleep(20);
            // Inits stopped.
            Assert.AreEqual("[]", Values.ToJson());
            Thread1.SwitchTo();
            Assert.AreEqual("[1]", Values.ToJson());
            Thread2.SwitchTo();
            Assert.AreEqual("[1,2]", Values.ToJson());
            Thread.Sleep(20);
            Thread1.SwitchTo();
            Assert.AreEqual("[1,2,3]", Values.ToJson());
            Thread2.SwitchTo();
            Assert.AreEqual("[1,2,3,4]", Values.ToJson());
        }
示例#2
0
        static void Test1(string[] args)
        {
            //new MyFastcgiServerAsync().Listen(8000);

            var Values = new List <int>();

            var Thread1 = new GreenThread();
            var Thread2 = new GreenThread();

            Thread1.InitAndStartStopped(() =>
            {
                Values.Add(1);
                Console.WriteLine(1);
                GreenThread.Yield();
                Console.WriteLine(3);
            });
            Thread2.InitAndStartStopped(() =>
            {
                Values.Add(2);
                Console.WriteLine(2);
                GreenThread.Yield();
                Console.WriteLine(4);
            });

            Console.WriteLine("a");
            Thread1.SwitchTo();
            Thread2.SwitchTo();
            Thread1.SwitchTo();
            Thread2.SwitchTo();
            Console.WriteLine("b");
            Console.ReadKey();
        }
示例#3
0
 void ICpuConnector.Yield(CpuThreadState CpuThreadState)
 {
     if (HleConfig.UseCoRoutines)
     {
         CoroutinePool.YieldInPool();
     }
     else
     {
         GreenThread.Yield();
     }
 }
示例#4
0
        /*
         * static public void TestMemset(CpuThreadState Processor)
         * {
         *((byte*)Processor.GetMemoryPtr(0x04000000)) = 0x77;
         * }
         */

        public void Yield()
        {
            //Console.WriteLine(StepInstructionCount);
            GreenThread.Yield();
            //Console.WriteLine(StepInstructionCount);
        }