public void load(Disk disk, RAM ram, pcbQueue pcbQueue) //Loads the next batch of jobs into RAM { while (pcbQueue.jobsComplete() == false && pcbQueue.ramIterator < 30) { int index = pcbQueue.ramIterator; //Starting load index is where the ramIterator currently points while (spaceAvailable(iterator, pcbQueue.queue[index].spaceReq, ram) == false) { //do nothing Thread.Yield(); } while (spaceAvailable(iterator, pcbQueue.queue[index].spaceReq, ram) == true) //It will stop loading when space is no longer available for next process { if (pcbQueue.ramIterator >= pcbQueue.queue.Length) { break; } loadRAM(disk, ram, pcbQueue, pcbQueue.ramIterator); } ram.calculateUsed(); if (debugMode) { Console.WriteLine("Percentage of RAM used: " + ram.percentageUsed + "%"); } iterator = 0; } }
public void execute(RAM ram, pcbQueue pcbQueue, Scheduler schedule, cpuQueue que) { while (pcbQueue.jobsComplete() == false) { while (this != que.head || pcbQueue.cpuIterator >= pcbQueue.ramIterator) { //do nothing if (pcbQueue.jobsComplete() == true) { return; } Thread.Yield(); } PCB temp = pcbQueue.queue[pcbQueue.cpuIterator]; if (debugMode) { Console.WriteLine("CPU " + this.id + " executing job " + temp.processID); } pcbQueue.cpuIterator++; que.deQueue(); temp.startTime = DateTime.Now.TimeOfDay; temp.waitTime = temp.startTime - temp.ramLoadTime; PopulateInstructionList(ram, temp); this.StartWork(temp); temp.timeCompleted = DateTime.Now.TimeOfDay; if (debugMode) { temp.core = pcbQueue.getCoreDump(temp, ram); } temp.executionTime = temp.timeCompleted - temp.startTime; temp.complete = true; this.signal(ram, schedule, temp); if (debugMode) { Console.WriteLine("Process " + temp.processID + " complete!"); } que.enQueue(this); if (debugMode) { Console.WriteLine("Jobs complete? " + pcbQueue.jobsComplete()); } } }