Student worksheet

Scheduling, Cores and Events

Three lesson sections: predict, build, explain. Work on paper or in the local lab. No name, account or student record is requested by the app.

25. Cooperative Scheduling

Take turns between tasks and distinguish policy from CPU instructions.

Open this lesson →

1. Predict and trace

Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.

LOAD 1
CALL taskA
CALL taskB
HALT
taskA: PRINT
SLEEP 500
RETURN
taskB: LOAD 101
PRINT
RETURN

Queue input: None

Initialize memory: All bytes initially zero

InstructionPC beforePC afterR0 beforeR0 afterRelevant stateOutput
       
       
       

2. Build and check

Read a number of rounds from 0 through 3. Start task A’s counter at 0 and task B’s at 100. Each round, call A to increment and print its counter, then B to increment and print its counter.

Required instruction types: INPUT, LOOP, CALL, RETURN

Starter program

INPUT
COPY R0 R3
LOAD 0 R1
LOAD 100 R2
LOOP R3
CALL taskA
CALL taskB
RETURN
HALT
taskA:
  # Advance R1, print, return.
RETURN
taskB:
  # Advance R2, print, return.
RETURN

Your program and notes

3. Explain the machine

Is CALL/RETURN turn-taking the same as hardware preemption?