Вопрос

I'm reading about event loops that pass messages, as I have to design one for a project I am working on. To understand it better, I am trying to analogize it to other things that I know somewhat better, to aid my understanding. Is the fetch / execute cycle of a CPU comparable at all to the event loop software construct? If not, what is the main difference (besides one being directly stored in hardware, of course). Thank you.

Это было полезно?

Решение

No, the two are not really similar.

In an event loop, the system has a queue that it reads from, and other processes can add items to the queue. These items are called messages or events, and they trigger action by the processor. Often the system allows multiple readers to wait on the queue, and they can register which types of events they're interested in, and the main event loop module doles them out appropriately.

The CPU fetch/execute cycle simply steps sequentially through memory, reading each instruction (fetch) and performing the appropriate action (execute).

The main difference is that events can be added to the event queue asynchronously, while fetch/execute is synchronous.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top