Difference between interrupt and event

22,140

Solution 1

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...)

Solution 2

Interrupts are implemented inside the hardware (CPU) to interrupt the usually linear flow of a program. This is important for external events like keyboard input but also for interrupting programs in multi-tasking operating systems.

Events are a means of software engineering and probably most often known from GUI toolkits. There, the toolkit/OS wraps happenings like keystrokes or mouse input into "events". Those are then dispatched to programs that went to register themselves for receiving such events. It's maybe a bit like a mailing system.

To compare both, from a userspace program view:

-Interrupts would force your program to halt in order to let some lower-level code execute (like OS code)

-Events usually are sent to you from lower-level code and trigger execution of your code

Share:
22,140
srikanth rongali
Author by

srikanth rongali

Updated on July 23, 2022

Comments

  • srikanth rongali
    srikanth rongali almost 2 years

    What is the difference between interrupt and an event?