Beispiel #1
0
        private void roundRobin() {
            //If something is not using the IO, and there is a waiting list, send it.
            if (usingDisk == null) {
                if (waitingDiskList.Count > 0) {
                    usingDisk = waitingDiskList.ElementAt(0);
                    usingDisk.status = "Using Disk";
                    waitingDiskList.RemoveAt(0);
                }
            }
            else {
                for (int i = 0; i < Pages.Length; i++) {
                    if (Pages[i].frame == null) {
                        try {
                            Pages[i].frame = usingDisk.framesLocation[usingDisk.curFrames];
                            Pages[i].frame.frameId = usingDisk.curFrames;
                            Pages[i].state = 0;
                            Pages[i].frame.location = "RAM";
                            Pages[i].timesUsed++;
                            Pages[i].timeAssigned = clock;
                            usingDisk.curFrames++;
                        }
                        catch { }
                    }
                    else if (Pages[i].state == 2) {
                        Pages[i].frame.location = "Memory";
                        Pages[i].frame.parent.framesDone++;
                        swapped.Add(Pages[i].frame);

                        Pages[i].state = 0;
                        Pages[i].frame = null;

                        try {
                            Pages[i].frame = usingDisk.framesLocation[usingDisk.curFrames];
                            Pages[i].frame.frameId = usingDisk.curFrames;

                            Pages[i].frame.location = "RAM";
                            Pages[i].timesUsed++;
                            Pages[i].timeAssigned = clock;
                            usingDisk.curFrames++;
                        }
                        catch { }
                    }
                }
                usingDisk.status = "Ready";
                readyList.Add(usingDisk);
                usingDisk = null;
            }

            if (waiting == null) {
                if (waitingList.Count > 0) {
                    waiting = waitingList.ElementAt(0);
                    waiting.status = "Using I/O";
                    waitingList.RemoveAt(0);
                }
            }

            //Keep waiting until IO_curTime = IO_totalTime
            else {
                if (waiting.IO_curTime >= waiting.IO_totalTime) {
                    if (waiting.cpuUse == waiting.curTime) {
                        waiting.status = "Terminated";
                        terminatedList.Add(waiting);
                    }
                    else {
                        waiting.status = "Ready";
                        readyList.Add(waiting);
                    }
                    waiting = null;
                }
                else {
                    waiting.IO_curTime++;
                }
            }
            //If nothing is running and there is something ready, send it over.
            if (running == null) {
                if (readyList.Count > 0) {
                    running = readyList.ElementAt(0);
                    running.status = "Running";
                    readyList.RemoveAt(0);
                }
            }
            //If somethign is running for the first time and it uses the IO, send it to the using IO
            else if (running.curTime == running.IO_initTime && running.usesIO) {
                running.curTime++;
                running.status = "Waiting for I/O";
                waitingList.Add(running);
                running = null;
            }
            //If the timer is still not the quantum, keep adding some cycles until its finished.
            else {
                if (quantumTimer < quantum) {
                    if (running.curTime < running.cpuUse) {
                        running.curTime++;
                    }
                    else if (running.framesDone >= running.frames) {
                        running.endTime = clock;
                        running.sysEndTime = running.endTime - running.arrivalTime + 1;
                        running.waitTime = running.sysEndTime - running.cpuUse - running.IO_totalTime + 1;
                        running.status = "Terminated";
                        terminatedList.Add(running);
                        running = null;
                    }
                    else {
                        running.status = "Waiting Disk";
                        waitingDiskList.Add(running);
                        running = null;
                    }
                }
                else {
                    running.status = "Ready";
                    readyList.Add(running);
                    running = null;
                }
            }
            //FCFS from new to ready
            if (newList.Count > 0 && readyList.Count < readyLimit) {
                newList.ElementAt(0).status = "Ready";
                readyList.Add(newList.ElementAt(0));
                newList.RemoveAt(0);
            }
        }
Beispiel #2
0
 public void Add(Process process) {
     newList.Add(process);
 }
Beispiel #3
0
        private void fcfs() {
            //Waiting Disk
            if (usingDisk == null) {
                if (waitingDiskList.Count > 0) {
                    usingDisk = waitingDiskList.ElementAt(0);
                    usingDisk.status = "Using Disk";
                    waitingDiskList.RemoveAt(0);
                }
            }
            else {
                for (int i = 0; i < Pages.Length; i++) {
                    if (Pages[i].frame == null) {
                        try {
                            Pages[i].frame = usingDisk.framesLocation[usingDisk.curFrames];
                            Pages[i].frame.frameId = usingDisk.curFrames;
                            Pages[i].state = 0;
                            Pages[i].frame.location = "RAM";
                            Pages[i].timesUsed++;
                            Pages[i].timeAssigned = clock;
                            usingDisk.curFrames++;
                        }
                        catch { }
                    }
                    else if (Pages[i].state == 2) {
                        Pages[i].frame.location = "Memory";
                        Pages[i].frame.parent.framesDone++;
                        swapped.Add(Pages[i].frame);

                        Pages[i].frame = null;
                        Pages[i].state = 0;

                        Pages[i].frame = usingDisk.framesLocation[usingDisk.curFrames];
                        Pages[i].frame.frameId = usingDisk.curFrames;

                        Pages[i].frame.location = "RAM";
                        Pages[i].timesUsed++;
                        Pages[i].timeAssigned = clock;
                        usingDisk.curFrames++;
                    }
                }
                usingDisk.status = "Ready";
                readyList.Add(usingDisk);
                usingDisk = null;
            }

            //If nothing is running, then send something from the readylist
            if (running == null) {
                if (readyList.Count > 0) {
                    running = readyList.ElementAt(0);
                    running.status = "Running";
                    readyList.RemoveAt(0);
                }
            }
            //If something is running, add a 1 to current time running, if its over then send it home
            else {
                if (running.cpuUse > running.curTime) {
                    running.curTime++;
                }
                else if (running.framesDone >= running.frames) {
                    running.endTime = clock;
                    running.IO_initTime = 0;
                    running.IO_totalTime = 0;
                    running.sysEndTime = running.endTime - running.arrivalTime + 1;
                    running.waitTime = running.sysEndTime - running.cpuUse - running.IO_totalTime + 1;
                    running.status = "Terminated";
                    terminatedList.Add(running);
                    running = null;
                }
                else {
                    running.status = "Waiting Disk";
                    waitingDiskList.Add(running);
                    running = null;
                }
            }
            if (newList.Count > 0 && readyList.Count < readyLimit) {
                newList.ElementAt(0).status = "Ready";
                readyList.Add(newList.ElementAt(0));
                newList.RemoveAt(0);
            }
        }