예제 #1
0
 public void runningToBlockedHandler(Process p)
 {
     Console.WriteLine("running to Blocked");
     Console.WriteLine(p.getProcessedTime());
     if (p.getSize() < Program.waitingQueue.getRemainingSize())
     {
         Program.waitingQueue.addQueue(p);
     }
     else
     {
         bool temp = false;
         for (int i = 0; i < Program.waitingQueue.getQueue().Count(); i++)
         {
             if (Program.waitingQueue.getQueue().ElementAt(i).getMeasuredPriority() < p.getMeasuredPriority())
             {
                 if (Program.waitingQueue.getQueue().ElementAt(i).getSize() <= p.getSize())
                 {
                     Process tempProcess = Program.waitingQueue.getQueue().ElementAt(i);
                     blockedToSuspendedBlockedHandler(tempProcess);
                     Program.waitingQueue.addQueue(p);
                     temp = true;
                     break;
                 }
             }
         }
         if (!temp)
         {
             Program.suspendedWaitingQueue.addQueue(p);
         }
     }
     if (!p.getIsDuplicateForIO())
     {
         Program.cpu.setIdle();
     }
 }
예제 #2
0
        public void perfomeCPU()
        {
            while (true)
            {
                lock (Program.o)
                {
                    if (!isIdle())
                    {
                        if (currentProcess.getIORequiredTimesQueue().Count() > 0)
                        {
                            if (currentProcess.getIORequiredTimesQueue().ElementAt(0) <= currentProcess.getProcessedTime() + count)
                            {
                                if (currentProcess.getThreadEnabled())
                                {
                                    currentProcess.getIORequiredTimesQueue().RemoveAt(0);
                                    Process thread = new Process(currentProcess.getName() + " t", currentProcess.getPriority(), currentProcess.getMeasuredTime(), currentProcess.getSize(), 0, true, true);
                                    Program.os.runningToBlockedHandler(thread);
                                    Program.newIOHandler.addToIOWaitingProcessesQueue(thread);
                                }
                                else
                                {
                                    newTimer.Enabled = false;
                                    Console.WriteLine("Blocked");
                                    Program.os.runningToBlockedHandler(currentProcess);
                                    currentProcess.setProcessedTime(currentProcess.getProcessedTime() + count);
                                    count = 0;
                                    Program.newIOHandler.addToIOWaitingProcessesQueue(currentProcess);

                                    setIdle();
                                }
                            }
                            else
                            {
                                if (currentProcess.getProcessedTime() + count >= currentProcess.getMeasuredTime())
                                {
                                    newTimer.Enabled = false;
                                    Program.finishedProcesses.addProcess(currentProcess);
                                    Program.agingHandler.removeProcess(currentProcess);
                                    currentProcess.setProcessedTime(currentProcess.getProcessedTime() + count);
                                    Console.WriteLine("process finished and processed time = " + currentProcess.getProcessedTime());
                                    count = 0;

                                    setIdle();
                                }
                                else if (count >= cPUBreakTimeIntervel)
                                {
                                    newTimer.Enabled = false;
                                    Console.WriteLine("time out****************************************** process getout processed time = " + currentProcess.getProcessedTime());
                                    currentProcess.setProcessedTime(currentProcess.getProcessedTime() + count);
                                    count = 0;
                                    Program.os.runningToReadyHandler();

                                    setIdle();
                                }
                            }
                        }
                        else
                        {
                            if (currentProcess.getProcessedTime() + count >= currentProcess.getMeasuredTime())
                            {
                                newTimer.Enabled = false;
                                Console.WriteLine("finished process");

                                Program.finishedProcesses.addProcess(currentProcess);
                                currentProcess.setProcessedTime(currentProcess.getProcessedTime() + count);
                                count = 0;

                                setIdle();
                            }
                            else if (count >= cPUBreakTimeIntervel)
                            {
                                currentProcess.setProcessedTime(currentProcess.getProcessedTime() + count);
                                Console.WriteLine("time out******************************************process getout processed time = " + currentProcess.getProcessedTime());
                                newTimer.Enabled = false;

                                count = 0;
                                Program.os.runningToReadyHandler();

                                setIdle();
                            }
                        }
                        if (newTimer.Enabled == false)
                        {
                            currentProcess.setTimeInQueue();
                            setIdle();
                        }
                    }
                }
            }
        }