Week 4 · Lesson 2 · 55 minutes

Schedule CPU time

I can compare scheduling using a precise small example.

Planned lesson. Follow your teacher’s teaching order.

Source workbook pages: 25.

Resources

Vocabulary

Vocabulary
process: a running program with its current state; time quantum: the maximum turn in round robin scheduling
55-minute lesson sequence
  1. 0–5 · Retrieve rapid switching.
  2. 5–15 · Act out the A3/B1 model with CPU-turn cards.
  3. 15–25 · Guide the FCFS task 1 line.
  4. 25–45 · Students build RR, compare C, and evaluate priority and multilevel queue policies.
  5. 45–50 · Check the seven slots and distinguish start from completion times.
  6. 50–55 · Collect the no-universal-winner exit.

Try before notes

Why can one CPU appear to run several apps at once?

Build the idea

A schedule states which ready process uses one CPU at each time. Record arrival order, CPU burst lengths, time quantum and switching cost before drawing it. Without these assumptions, two timelines may be answering different questions.

FCFS runs ready jobs in arrival order. Round robin gives each ready job up to one quantum, then moves unfinished work to the back. A short job may respond sooner, but not every job finishes sooner.

First response is the time before a job first runs. Completion time is when it finishes. Waiting and turnaround are different measures. State which measure your judgement uses.

ready queue → CPU for one turn
 unfinished ← back of queue
 finished → leave queue

See the method

Use one CPU. All processes arrive at time 0. Ignore switching cost. FCFS serves arrival order. Round robin gives each ready process a short turn, then returns unfinished work to the queue. For A=3 and B=1 time units, FCFS A then B finishes B at 4. Round robin with quantum 1 finishes B at 2.

Predict then reveal

A needs 2 units, B needs 3; both arrive at 0 in A,B order. Compare FCFS and RR quantum 1, zero switch cost.

Reveal reasoning

FCFS: A 0–2, B 2–5; completions A=2,B=5. RR: A 0–1,B 1–2,A 2–3,B 3–4,B 4–5; completions A=3,B=5. B first responds at 1 instead of 2, while A finishes later.

Why can an extremely small quantum reduce useful throughput when switches take time?

Reveal reasoning

Each switch consumes time preserving and restoring state rather than completing the jobs. Shorter turns cause more switches for the same work, increasing overhead. Responsiveness must be balanced against that cost.

Work one step together

Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.

Practice

  1. Processes A=4, B=2, C=1 arrive together in A,B,C order. Draw FCFS and round robin timelines with quantum 1. State each completion time and compare the first response for C.

Your turn

Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.

Practice

  1. Processes A=4, B=2, C=1 arrive together in A,B,C order. Draw FCFS and round robin timelines with quantum 1. State each completion time and compare the first response for C.
  2. Priority scheduling always picks the highest-priority ready job. A multilevel queue separates types of work into queues with a stated policy. Explain a benefit and a fairness risk of each. Give one way to reduce starvation.

Check and explain

Round robin is not universally faster. Compare the chosen metric and include overhead assumptions.

Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.

Show what you know

Does round robin always finish every process sooner than FCFS?

HL challenge when ready

If every switch costs time, what can a very small quantum do?

Week 4 homework

Show working. Keep code and output. Stop at 25 minutes and mark where you reached.

  1. All jobs arrive at 0 in order A,B. A needs 5 units and B needs 2. Draw FCFS and round robin with quantum 2. Ignore switch cost. Give completion times. Python retrieval: start queue = ["A","B","C"]. Move unfinished A from front to back. Predict, then print the queue.
  2. A device generates rare events while its controller sleeps. Recommend polling or interrupts with one benefit and one limitation.
  3. Explain one deadlock using two processes and two resources. Give a change that breaks the problem.
  4. Explain why a bytecode interpreter and a compiler can both be part of one language implementation.

Source workbook pages: 29.

Weekly homework (Word)

Python practice · two short prompts

Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.

A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.

Prompt 1

Calculate finish times for a first-come-first-served schedule. Swap the first two jobs.

No imports needed.

Hint and starter code

Assume all jobs arrive at time zero and no switching cost.

# Assume all jobs arrive at time zero and no switching cost.
jobs = [("A", 4), ("B", 2), ("C", 1)]
time = 0
for name, duration in jobs:
    time += duration
    print(name, time)
Open this starter in Python playground →
Prompt 2

Give each job one time slice and print the work remaining.

No imports needed.

Hint and starter code

A time slice (quantum) is the maximum CPU time allowed before another job gets a turn.

# A time slice (quantum) is the maximum CPU time allowed before another job gets a turn.
remaining = [5, 2, 1]
quantum = 2
for work in remaining:
    print(max(0, work - quantum))
Open this starter in Python playground →