private static void PreemptingExampleNonPreemptingSchedulerMultipleTasks() { int numOfThreads = 2; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreateNonPreemptive(numOfThreads); SimpleTaskScheduler.ExecutionToken token1 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token2 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token3 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token4 = taskScheduler.GetExecutionToken(); Task t1 = CreateTask(id: 1, token: token1); Task t2 = CreateTask(id: 2, token: token2); Task t3 = CreateTask(id: 3, token: token3); Task t4 = CreateTask(id: 4, token: token4); taskScheduler.Register(t1, 5, 2500, token1); taskScheduler.Register(t2, 4, 2500, token2); taskScheduler.Register(t3, 3, 2500, token3); taskScheduler.Register(t4, 2, 2500, token4); t1.Start(taskScheduler); t2.Start(taskScheduler); Task.Delay(1000).Wait(); t3.Start(taskScheduler); t4.Start(taskScheduler); taskScheduler.FinishScheduling(); }
public void TestCreationOfNonPreemptiveSimpleTaskSchedulerWithTwoThreads() { int numberOfThreads = 2; SimpleTaskScheduler st = SimpleTaskScheduler.CreateNonPreemptive(numberOfThreads); Assert.AreEqual(numberOfThreads, st.GetMaxParallelTasks()); Assert.AreEqual(false, st.IsSchedulerPreemptive()); }
private static void BaseClassExample() { int numOfThreads = 1; TaskScheduler taskScheduler = SimpleTaskScheduler.CreateNonPreemptive(numOfThreads); Task t = CreateTask(id: 1); t.Start(taskScheduler); ((SimpleTaskScheduler)taskScheduler).FinishScheduling(); }
public void TestCreationOfNonPreemptiveSimpleTaskSchedulerWithZeroThreads() { int numberOfThreads = 0; try { SimpleTaskScheduler st = SimpleTaskScheduler.CreateNonPreemptive(numberOfThreads); Assert.Fail(); } catch (ArgumentOutOfRangeException ex) { } }
public void TestSchedulingOfNonPreemptiveUsingBaseClassShouldSucceedQueueing() { int numOfThreads = 2; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreateNonPreemptive(numOfThreads); TaskScheduler baseTaskScheduler = taskScheduler; Task t = CreateTask(id: 1, token: taskScheduler.GetExecutionToken()); t.Start(baseTaskScheduler); Task.Delay(500).Wait(); Assert.IsTrue(taskScheduler.IsTaskCurrentlyExecuting(t)); }
private static void SingleThreadPreemptingExampleNonPreemptingScheduler() { int numOfThreads = 1; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreateNonPreemptive(numOfThreads); SimpleTaskScheduler.ExecutionToken token1 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token2 = taskScheduler.GetExecutionToken(); Task t1 = CreateTask(id: 1, token: token1); Task t2 = CreateTask(id: 2, token: token2); taskScheduler.Register(t1, 5, 2500, token1); taskScheduler.Register(t2, 4, 2500, token2); t1.Start(taskScheduler); Task.Delay(1000).Wait(); t2.Start(taskScheduler); taskScheduler.FinishScheduling(); }