1
$\begingroup$

Are Interrupts really just an abstracted form of polling?

I saw a system-file-watcher library that stated it used polling, as opposed to listening for events. Is the .NET framework SystemFileWatcher class just an abstraction of polling?

In a computer, interrupts are stacked, and the CPU checks the interrupt stack after every cycle, so this is pretty much polling, right? - Albeit more efficient than checking every individual device.

$\endgroup$
  • $\begingroup$ The notion of "checking after each cycle" is a rather outdated model, certainly in this century with multi-core CPU's which have multiple independent cycles. The first question to answer is, which core should handle the interrupt? This can depend on the interrupt itself - one interrupt may be best handled by a core that's executing code related to that interrupt (e.g. a disk read complete interrupt), while another interrupt might best be handled by an idle core. (e.g. packet arrived on Ethernet controller). $\endgroup$ – MSalters Mar 15 '17 at 11:00
1
$\begingroup$

Not really.

Polling requires CPU cycles to poll a device and respond if needed. Detecting interrupts takes up no extra CPU cycles and is almost always done in parallel with instructions being executed. CPU cycles are only used up in servicing the interrupt.

Also, with polling, you have a control over how and when you poll devices whereas interrupts are generally out of sync with the program (or at least, you cannot exert too much control over when they arrive).

The mindset behind polling driven and interrupt driven code/architecture is entirely different.

$\endgroup$
  • $\begingroup$ The mindsets may be "entirely different" but the actual implementations may be mixed. A common implementation is that an interrupt sets a flag, and code polls whether the flag has already been set. The logic behind this setup is that setting the flag is a simple and safe operation which can be done at almost any time. $\endgroup$ – MSalters Mar 15 '17 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.