Closed ghost closed 8 years ago
You're right that the main thing runPCB does is primarily set isRunningProcess to true. Whenever the HLT instruction is fetched from the CPU, isRunningProcess is set back to false. With the Threaded CPU update, I moved the initializeCPU() method to be ran automatically, immediately after isRunningProcess is set to true. The variable isRunningProcess should still be set to false, when the CPU fetches the HLT instruction.
Ok, thanks for responding. I'm not sure why my findCPU() method isn't being told when a CPU has finished with a job. I added print statements before and after the halt statement in your code:
switch (opcode) {
case 0x12:
System.out.println("Before: " + isRunningProcess());
isRunningProcess = false;
System.out.println("After: " + isRunningProcess());
break;
case 0x14:
cpuState.setPc(addr);
break;
}
When I choose to run 1 CPU, neither statement prints. When I choose more than 1 CPU, this is what prints:
2 CPUs were created.
PCBs were left in FIFO order.
Before: true
After: true
------------------------
4 CPUs were created.
PCBs were left in FIFO order.
Before: true
After: true
------------------------
8 CPUs were created.
PCBs were left in FIFO order.
Before: true
After: true
I was trying to figure out why there's an infinite loop in my
ShortTermScheduler()
(that we talked about yesterday), What doesrunPCB()
do, exactly? I may be misinterpreting this, but it looks like it only changes the booleanisRunningProcess
to true. In older code,runPCB()
calledinitializeCPU()
, but that's no longer in therunPCB()
method.public void runPCB(PCB pcb) { currentPCB = pcb; isRunningProcess = true; }
I'm wondering if that's why my
findCPU()
can't find a CPU - once a CPU is assigned a job, "isRunningProcess
" is never switched back to false. What do you think?