A1.3.4 Polling vs interrupts: which is better when?
SL + HLCommand term: Evaluate1. Polling vs interrupts: race simulator
A device produces events (), such as key presses or arriving network data. Polling: the CPU keeps asking the device "anything new?" every few ticks. Interrupts: the device tells the CPU the moment something happens. Pick a scenario or set the sliders, then step through 60 ticks.
2. What happens during an interrupt?
Click Next to follow the CPU as it handles a key-press interrupt.
3. Evaluate: polling or interrupts?
For each real-world scenario, choose the better approach. The explanation names the factors from the syllabus. Score: 0 /
Learning objectives
By the end of this page you should be able to:
- Describe how polling works.
- Describe how interrupts and interrupt handling work.
- Compare polling and interrupts by event frequency, CPU overhead, power source, predictability, latency and security.
- Evaluate the use of polling or interrupts in real-world scenarios such as keyboard and mouse input, network communications and disk I/O.
- Justify the choice of polling or interrupts for embedded and real-time systems.
Polling
The CPU repeatedly checks the status of a device at regular intervals ("Are you ready? Anything new?"). It is simple and predictable, but the CPU wastes time checking when nothing has happened, and an event may wait until the next check.
Interrupts
The device sends an interrupt signal to the CPU when it needs attention. The CPU finishes its current instruction, saves its state (PC and registers) on the stack, runs an interrupt service routine (ISR), then restores its state and carries on. Interrupts can have priorities, so urgent ones are handled first.
Evaluation by factor
| Factor | Polling is better when… | Interrupts are better when… |
|---|---|---|
| Event frequency | events are very frequent: there is almost always something new, so checks are rarely wasted and repeated interrupt overheads are avoided | events are rare: no CPU time is wasted checking an idle device |
| CPU processing overheads | each check is cheap and there's no context switching | avoiding constant checks matters more than the small cost of saving and restoring state for each interrupt |
| Power source | the device is on mains power and the CPU is busy anyway | it runs on battery: the CPU can sleep until an interrupt wakes it |
| Event predictability | events are regular / predictable, so polls can be timed to match them | events are unpredictable, e.g. a user pressing a key |
| Controlled latency | a fixed, guaranteed response time is needed (deterministic timing in some safety-critical loops) | the fastest possible response to unpredictable events is needed |
| Security concerns | a simpler, predictable design is easier to verify; a flood of interrupts can't overwhelm the CPU | handlers must be protected: malicious devices or software could cause interrupt storms (a form of denial of service), or exploit ISR code that runs with high privilege |
Typical real-world choices
- Keyboard and mouse: interrupts (unpredictable, relatively rare events; the user expects an instant response).
- Network communications: interrupts for normal traffic; under very heavy traffic, network cards often switch to polling to avoid an interrupt for every packet.
- Disk input/output: interrupts signal that a slow read/write has finished, so the CPU can do other work meanwhile.
- Embedded systems: simple, regular sensors are often polled; battery devices use interrupts so they can sleep.
- Real-time systems: prioritised interrupts for urgent events (e.g. an airbag crash sensor); polling where a fixed, predictable cycle is required.
Use the 中文 button at the top to show or hide the Chinese terms.
| Term | 中文 | Meaning |
|---|
Choose an answer. You get instant feedback.
Score: 0 /
Write your answer first, then reveal the markscheme. These are exam-style practice questions written for this site.
1. Distinguish between polling and interrupt handling. [2]
2. Describe the steps the CPU takes when it receives an interrupt. [4]
3. Explain why interrupts are more suitable than polling for the keyboard of a battery-powered laptop. [3]
4. A network card in a busy data centre receives millions of packets per second. Evaluate the use of polling instead of interrupts in this scenario. [4]
5. Outline one security concern related to interrupt handling. [2]