Exercise 1: A Single Process With No One Else Waiting — Possible Solution ==================================================================== THE TEST ------------------------------ solo = kernel.create_process(num_pages=1) solo.transition(ProcessState.RUNNING) result = run_cooperative(cpu, scheduler, solo) # scheduler.ready_queue is empty RESULT ------------------------------ same PCB object returned: True process state after 'yielding' with no one else waiting: ProcessState.RUNNING result is solo (the identical object, not a copy), and its state is still RUNNING -- it never even passed through READY. WHY NOTHING HAPPENS ------------------------------ run_cooperative()'s very first line is: next_pcb = scheduler.pick_next() if next_pcb is None: return current_pcb pick_next() returns None the moment self.ready_queue is empty. With next_pcb equal to None, the function returns immediately -- it never reaches context_switch_fixed(), which means it never calls old_pcb.transition(ProcessState.READY), never calls new_pcb.transition(ProcessState.RUNNING) on anything, and never touches cpu.registers at all. The "yield" is a genuine no-op. WHY THIS IS THE RIGHT BEHAVIOR, NOT A MISSING FEATURE ------------------------------ A real kernel gains nothing by performing a full save-and-restore cycle when the process being restored is the exact same one that was just saved -- it would burn real CPU cycles copying a register dictionary into itself for no observable effect. Skipping the switch entirely when there's genuinely no one else ready to run is the correct optimization, not a shortcut that happens to work. WHY THIS WORKS AS AN ANSWER ------------------------------ Checking both the returned object's identity (is, not just equality) and its state confirms two separate things at once: that no context switch occurred at all (same object, same state), and that the process's own state machine was never touched in the process -- exactly what "no-op" should mean for a function that claims to perform a full context switch whenever there IS a next process to run.