Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are polling and event-driven programming different words for the same technique?

I studied interrupts vs cyclical polling and learnt the advantages of interrupts that don't have to wait for a poll. Polling seemed to me just like event-driven programming or at least similar to a listener and what the polling does is actually much like listening to input or output. Do you agree or did I misunderstand any crucial difference between polling (cyclical listening) and event-driven programming (also listening with so-called listeners)?

like image 476
Niklas Rosencrantz Avatar asked Nov 26 '12 02:11

Niklas Rosencrantz


People also ask

Which is better in polling and events?

While a polled operation is simple to program, it is generally advisable to use event-driven operations because they are more portable, robust, and less dependent on the operating system timing.

What do you mean by an event-driven programming?

In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or message passing from other programs or threads.

What is meant by event polling?

Polling a device means regularly getting the current state of the device objects or checking the contents of the event buffer.

What is the difference between polling and interrupt?

The main difference between interrupt and polling is that, in the case of an interrupt, the system informs the CPU that it needs attention, while talking about polling, the CPU constantly inspects the status of the system to find whether it needs attention.


1 Answers

Nope, quite the contrary interrupt driven programming is pretty much what event driven programming is at the hardware level. Both interrupt driven code and event driven code waits for event before running a code, while polling will attempt to query for event whether or not one actually exists.

However, it should be noted that interrupt- and event-driven programs are generally implemented in the lower level using a form of polling; there is no truly interrupt or event driven system that does not involve some sort of polling, although usually in hardware. In the case of interrupts, the CPU actually polls the interrupt line every clock cycle, and likewise with event driven programming because restarting a paused thread involves an interrupt being raised by the source of event (usually drivers).

You can say that interrupt- and event- driven programming is a disciplined way to poll that have lots of advantage compared to actually doing polling yourself.

like image 105
Lie Ryan Avatar answered Sep 21 '22 21:09

Lie Ryan