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()); }
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(); }
public void Step(int InstructionCountForYield = 1000000) { CpuThreadState.StepInstructionCount = InstructionCountForYield; //this.MinimalInstructionCountForYield = InstructionCountForYield; GreenThread.SwitchTo(); }