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(); }
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(); }
private static void PriorityInversionExample2() { int numOfThreads = 1; SimpleTaskScheduler taskScheduler = SimpleTaskScheduler.CreatePreemptive(numOfThreads); SimpleTaskScheduler.ExecutionToken token1 = taskScheduler.GetExecutionToken(); SimpleTaskScheduler.ExecutionToken token2 = taskScheduler.GetExecutionToken(); Object resource = new Object(); Task t1 = CreateTaskWithResourceLockAndUnlockResource(id: 1, token: token1, resource); Task t2 = CreateTaskWithResourceLockAndUnlockResource(id: 2, token: token2, resource); taskScheduler.Register(t1, 5, 2500, token1); taskScheduler.Register(t2, 4, 2500, token2); t1.Start(taskScheduler); Task.Delay(1000).Wait(); t2.Start(taskScheduler); taskScheduler.FinishScheduling(); }