mtfuller / os-team-project

This is the main repository for the OS Team Project for CS 3502.
0 stars 0 forks source link

CPU question #28

Closed ghost closed 8 years ago

ghost commented 8 years ago

I was trying to figure out why there's an infinite loop in my ShortTermScheduler()(that we talked about yesterday), What does runPCB() do, exactly? I may be misinterpreting this, but it looks like it only changes the boolean isRunningProcess to true. In older code, runPCB() called initializeCPU(), but that's no longer in the runPCB() 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?

mtfuller commented 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.

ghost commented 8 years ago

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