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 HleThread(PspEmulatorContext PspEmulatorContext, CpuThreadState CpuThreadState) { this.HleInterruptManager = PspEmulatorContext.GetInstance<HleInterruptManager>(); this.HleThreadManager = PspEmulatorContext.GetInstance<HleThreadManager>(); this.MethodCache = CpuThreadState.CpuProcessor.MethodCache; this.PspConfig = CpuThreadState.CpuProcessor.PspConfig; if (this.PspConfig.UseCoRoutines) { this.Coroutine = HleThreadManager.Processor.CoroutinePool.CreateCoroutine(this.Name, MainLoop); } else { this.GreenThread = new GreenThread(); GreenThread.InitAndStartStopped(MainLoop); } this.CpuThreadState = CpuThreadState; }
public HleThread(InjectContext InjectContext, CpuThreadState CpuThreadState) { InjectContext.InjectDependencesTo(this); //this.PspConfig = CpuThreadState.CpuProcessor.CpuConfig; if (this.HleConfig.UseCoRoutines) { this.Coroutine = HleThreadManager.CoroutinePool.CreateCoroutine(this.Name, MainLoop); } else { this.GreenThread = new GreenThread(); GreenThread.InitAndStartStopped(MainLoop); } this.CpuThreadState = CpuThreadState; }