Week 4 · Lesson 4 · 55 minutes

Polling and interrupts

I can choose an event-handling method for a stated need.

Planned lesson. Follow your teacher’s teaching order.

Source workbook pages: 27.

Resources

Vocabulary

Vocabulary
polling: checking a device repeatedly for an event; interrupt: a signal that requests the processor’s attention
55-minute lesson sequence
  1. 0–5 · Retrieve scheduling.
  2. 5–15 · Model the two event paths and define latency.
  3. 15–25 · Place the event on the task 1 timeline and distinguish persistent from brief signals.
  4. 25–45 · Students justify both scenario choices using at least three criteria.
  5. 45–50 · Partner looks for absolute words such as always, never and instant.
  6. 50–55 · Collect the interrupt-latency explanation.

Try before notes

What does scheduling try to share?

Build the idea

Polling asks repeatedly whether a device needs attention. If the event remains pending, it is found at the next check. If a brief event disappears between checks, a polling system may miss it unless hardware records it.

An interrupt signals that attention is needed. The processor handles it when priorities and current conditions allow, preserves needed state, runs a handler and resumes work. Arrival does not guarantee immediate handling.

Compare event frequency, timing needs, energy and overhead. Rare events may suit interrupts. Regular sampling may suit scheduled checks. Many systems combine both approaches rather than choosing one forever.

poll: check → work → check → work
interrupt: work → signal → handler → resume

See the method

A controller can check a switch every 10 milliseconds. That is polling. A device can instead raise an interrupt when an event occurs. The CPU may pause current work, preserve necessary state, run a handler and resume. Polling spends time checking even when nothing happens. Interrupts have handling overhead and need careful priority and security controls.

Predict then reveal

Checks occur at 0,8,16,24 ms. An event starts at 10 ms and stays pending. When is it detected and what is its delay?

Reveal reasoning

The next check is at 16 ms. Detection delay is 16−10=6 ms. The answer assumes the event remains recorded until that check.

What if the event exists only from 10 to 11 ms?

Reveal reasoning

The 8 ms check is too early and the 16 ms check too late. It may be missed. A latched event flag that stays set until read, faster appropriate sampling, or suitable interrupt hardware could change that result.

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. A polling check occurs at 0,10,20,30 ms. An event occurs at 11 ms and remains set. When is it first detected? What if the event begins at 11 and disappears at 12 ms? State an assumption that could prevent missing it.

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. A polling check occurs at 0,10,20,30 ms. An event occurs at 11 ms and remains set. When is it first detected? What if the event begins at 11 and disappears at 12 ms? State an assumption that could prevent missing it.
  2. Compare a battery keyboard with rare key presses and a controller sampling a predictable signal at fixed times. Recommend an approach for each. Include event frequency, timing, overhead and one risk.

Check and explain

An interrupt is a request for attention, not a guarantee of zero delay.

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

Is an interrupt always handled at the instant it arrives?

HL challenge when ready

Why can a flood of interrupts be harmful?

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

Count repeated checks until an event is ready. Move True earlier.

No imports needed.

Hint and starter code

Polling repeatedly asks whether something is ready.

# Polling repeatedly asks whether something is ready.
ready = [False, False, True]
checks = 0
for state in ready:
    checks += 1
    if state:
        break
print(checks)
Open this starter in Python playground →
Prompt 2

Handle only listed events instead of checking every moment. Add a second event type.

No imports needed.

Hint and starter code

An interrupt signals that attention is needed. This event list illustrates handling, not real hardware interrupts.

# An interrupt signals that attention is needed.
events = ["key", "timer"]
for event in events:
    print("handle", event)
Open this starter in Python playground →