本文介绍了中断和事件之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中断和事件有什么区别?

解决方案

这两个概念都为系统/程序"提供了处理某些程序正常展开期间发生的各种条件"的方式,并且在返回(或不返回)原始任务之前,可能需要系统/程序"执行其他操作.但是,除了功能相似之外,它们还是在不同的上下文中,在不同的级别使用的非常不同的概念.

中断提供了一个低级设备来中断在给定时间内CPU正在运行的任何程序的正常展开,并使CPU开始处理说明在另一个地址.中断对于处理需要CPU立即处理的各种情况(例如,处理击键或新数据到达串行通信通道)很有用.

许多中断是由硬件(通过某些电子设备更改CPU的一个引脚上的极性)产生的,但是也有软件中断,这些中断是由程序本身调用特定指令引起的. (或者通过CPU检测到某些东西本身或正在运行的程序误入歧途).

一个非常著名的中断是INT 0x21,该程序调用[d]从MS-DOS调用服务.

通常通过向量表来分配中断,由此CPU在内存中的特定位置包含一个地址数组(特定中断处理程序所在的位置).通过修改中断表的内容(如果允许的话...),程序可以重新定义对于给定的中断号将调用哪个特定的处理程序.

另一方面,

事件系统/语言级的消息" ,可用于表示各种硬件或软件情况(我会使用单词事件),例如鼠标单击,键盘输入,还包括应用程序级别的情况,例如模块化数据库中的新记录"或高度摘要的请求和消息,这些都在模块化程序中用于程序各个部分之间的通信/请求. /p>

与具有完全由CPU定义的[相对简单]行为的中断不同,在操作系统以及各种框架(例如:MS Windows,JavaScript,.NET, GUI框架,例如QT等.).所有事件系统虽然实现方式不同,但通常会共享诸如

之类的通用属性.
  • 处理程序的概念,它是程序的特定功能/方法,用于处理来自特定事件源的特定类型的事件.
  • 事件的概念,它是一种[通常很小的]结构,包含有关事件的信息:其类型,其来源,自定义参数(其语义取决于事件类型)
  • 一个队列,其中事件由源插入并由使用者/处理程序(或更确切地说,由调度程序(取决于系统...)进行轮询)

What is the difference between interrupt and an event?

解决方案

These two concepts both offer ways for the "system/program" to deal with various "conditions" which take place during the normal unrolling of some program, and which may require the "system/program" to do something else, before returning (or not...) to the original task. However, aside from this functional similarity, they are very distinct concepts used in distinct contexts, at distinct levels.

Interrupts provide a low-level device to interrupting the normal unrolling of whatever piece of program the CPU is working on a a given time, and to have the CPU start processing instructions at another address. Interrupts are useful to handle various situations which require the CPU's immediate processing (for example to deal with keystrokes, or the arrival of new data in a serial communication channel).

Many interruptions are produced by hardware (by some electronic device changing the polarity on one of the pins of the CPU), but there are also software interrupts which are cause by the program itself invoking a particular instruction. (or also by the CPU detecting something is astray with regard to itself or the program running).

A very famous interrupt is INT 0x21 which program invoke[d] to call services from MS-DOS.

Interrupts are typically dispatched by way of vector tables, whereby the CPU has a particular location in memory containing an array of addresses [where particular interrupt handlers reside]. By modifying the content of the interrupt table [if it is so allowed...], a program can redefine which particular handler will be called for a given interrupt number.

Events, on the other hand, are system/language-level "messages" which can be used to signify various hardware or software situations (I'd use the word event), such as Mouse clicks, keyboard entries, but also application-level situations such as "New record inserted in database" or highly digested requests and messages, used in modular programs for communication/requests between various parts of the program.

Unlike interrupts with their [relatively simple] behavior which is fully defined by the CPU, there exist various event systems systems, at the level of the operating system as well as various frameworks (ex: MS Windows, JavaScript, .NET, GUI frameworks like QT etc..). All events systems, while different in their implementations, typically share common properties such as

  • the concept of a handler, which is a particular function/method of the program which is designated to handle particular types of event from particular event sources.
  • the concept of an event, which is a [typically small] structure containing information about the event: its type, its source, custom parameters (which semantics depend on the event type)
  • a queue where events are inserted by sources and polled by consumers/handlers (or more precisely by dispatchers, depending on system...)

这篇关于中断和事件之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:16