Polling repeatedly checks a device or condition to determine whether it requires attention. Interrupt handling allows a device or event to signal the processor, which temporarily suspends its current task and executes an interrupt service routine (ISR).
How each method works
During polling, the processor follows a loop:
- Check the status of a device or sensor.
- Process the event if the device is ready.
- Otherwise, continue checking.
For example, a control system may repeatedly check whether a temperature sensor has exceeded a threshold. This is straightforward, but processor time is used even when the sensor's status has not changed.
With interrupt handling, the processor continues other work until an event produces an interrupt request. The operating system or processor then:
- Completes or pauses the current instruction.
- Saves the current process state.
- Executes the relevant ISR.
- Restores the saved state and resumes the previous task.
| Factor | Polling | Interrupt handling |
|---|---|---|
| Event detection | Processor repeatedly checks status | Device or event signals the processor |
| CPU efficiency | Can waste processing time | CPU can perform other tasks while waiting |
| Response | Depends on polling frequency | Usually prompt, subject to interrupt priority and latency |
| Complexity | Simpler to design and predict | Requires ISRs, state saving, and interrupt management |
| Best suited to | Regular, frequent, or predictable checks | Irregular or urgent events |
A common misconception is that interrupts always respond instantly. In reality, interrupt latency occurs between the interrupt request and execution of its ISR. Higher-priority interrupts may also be handled first.