问题描述
我研究了中断与周期性轮询的关系,并了解了不必等待轮询的中断的优点.在我看来,轮询就像事件驱动的编程一样,或者至少类似于侦听器,而轮询所做的实际上就像侦听输入或输出.您同意还是误解了轮询(周期性侦听)与事件驱动的编程(也称为所谓的侦听器)之间的重要区别?
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)?
推荐答案
不,相反,中断驱动的编程与事件驱动的编程在硬件级别上差不多.中断驱动代码和事件驱动代码都在运行代码之前等待事件,而轮询将尝试查询事件是否确实存在.
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.
但是,应该注意的是,中断和事件驱动程序通常是通过轮询的方式在较低级别上实现的;尽管通常在硬件中,没有真正的中断或事件驱动的系统不涉及某种轮询.对于中断,CPU实际上会在每个时钟周期轮询中断线,并且同样使用事件驱动的编程,因为重新启动暂停的线程会导致事件源(通常是驱动程序)引发中断.
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.
这篇关于对于相同的技术,轮询和事件驱动的编程是否有不同的用语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!