예제 #1
0
            internal override void Execute()
            {
                int currentlyExecutingTasksCount = scheduler.CurrentlyExecutingTasksCount();

                Task minPriorityNonExecutingTask = scheduler.FindMinimumPriorityNonExecutingTask();

                if (minPriorityNonExecutingTask == null)
                {
                    return;
                }

                if (currentlyExecutingTasksCount < scheduler.MaxParallelTasks)
                {
                    //start min priority non executing task, we have a free thread
                    scheduler.ContinueStartTask(task: minPriorityNonExecutingTask, threadId: scheduler.FindFirstFreeThread());
                }
                else if (scheduler.IsPreemptive)
                {
                    //search for task which could be stopped
                    Task maxPriorityExecutingTask = scheduler.FindMaximumPriorityExecutingTask();

                    if (scheduler.ComparePriorities(minPriorityNonExecutingTask, maxPriorityExecutingTask) < 0)
                    {
                        int threadId = scheduler.GetThreadOfTask(maxPriorityExecutingTask);
                        scheduler.PauseTask(maxPriorityExecutingTask);
                        scheduler.ContinueStartTask(minPriorityNonExecutingTask, threadId);
                    }
                }
            }