事件驱动的编程是如何实现的? [英] How is event driven programming implemented?

查看:122
本文介绍了事件驱动的编程是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何扭曲和Node.js的框架工作,我
试图准确地了解操作系统如何支持I / O
使用回调操作。

I was looking on how the twisted and node.js frameworks work and I am trying to understand exactly how the operating system supports I/O operations using callbacks.

我知道这是一件好事,因为我们需要更少的线程,因为我们不
需要有阻塞的线程在等待I / O操作。但一些
有一次,在I / O完成后调用回调。

I understand it's good because we need less threads because we don't need to have blocked threads waiting for I/O operations. But something has to call the callback once the I/O is finished.

这是如何由操作系统执行?

How is this implemented by the operating system?

推荐答案

一种方法是让OS附加任何人等待回调到相关的数据结构,如内核中的等价物的文件描述符的信息,你'再等待有关读取通知。当有事到该文件描述,操作系统扫描服务员,看是否有应得到通知。如果他们应该,那么它这样做。您可以了解一个实现的这柠檬的论文介绍FreeBSD的的kqueue 机制。具体见第6,实施,则第3和第4,活动的事件来源和交货。

One approach is to have the OS attach information about anyone waiting for a callback to the relevant data structure, such as the in-kernel equivalent of the file descriptor you're waiting for read notification about. When something happens to that file descriptor, the OS scans the waiters to see if any should be notified. If they should, then it does so. You can read about one implementation of this in Lemon's paper introducing FreeBSD's kqueue mechanism. See in particular section 6, "Implementation", subsections 3 and 4, "Activity on Event Source" and "Delivery".

这篇关于事件驱动的编程是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆