/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _tempProcessId = -1; int _shortest = int.MaxValue; bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (ReadyQueue[_index].IsStarted && !ReadyQueue[_index].IsCompleted && ReadyQueue[_index].ExpectedCPUBurst < _shortest && ReadyQueue[_index].EnterTime < Counter) { _tempProcessId = _index; _shortest = ReadyQueue[_index].Burst; } } if (_tempProcessId >= 0) { Process _executedProcess = ExecuteProcess(ReadyQueue[_tempProcessId]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } else { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _tempProcessId = -1; int _minEnter = Counter + 1; //Process entering later than Clock is under IO or waiting. bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (ReadyQueue[_index].IsStarted && !ReadyQueue[_index].IsCompleted && ReadyQueue[_index].EnterTime < _minEnter) { _tempProcessId = _index; _minEnter = ReadyQueue[_index].EnterTime; } } if (_tempProcessId >= 0) { Process _executedProcess = ExecuteProcess(ReadyQueue[_tempProcessId]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } else { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _processId = -1; bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (!ReadyQueue[_index].IsCompleted && ReadyQueue[_index].EnterTime < Counter) { Counter += ContextSwitch; CPUWaitingTime += ContextSwitch; _processId = _index; Process _executedProcess = ExecuteProcess(ReadyQueue[_index]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } } if (_processId.Equals(-1)) { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }