问题描述
我一直在寻找如何扭曲和Node.js的框架工作,我
试图准确地了解操作系统如何支持I / O
使用回调操作。
I was looking on how the twisted and node.js frameworks work and I amtrying to understand exactly how the operating system supports I/Ooperations using callbacks.
我知道这是一件好事,因为我们需要更少的线程,因为我们不
需要有阻塞的线程在等待I / O操作。但一些
有一次,在I / O完成后调用回调。
I understand it's good because we need less threads because we don'tneed to have blocked threads waiting for I/O operations. But somethinghas to call the callback once the I/O is finished.
这是如何由操作系统执行?
How is this implemented by the operating system?
推荐答案
一种方法是让OS附加任何人等待回调到相关的数据结构,如内核中的等价物的文件描述符的信息,你'再等待有关读取通知。当有事到该文件描述,操作系统扫描服务员,看是否有应得到通知。如果他们应该,那么它这样做。您可以了解一个实现的这。具体见第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".
这篇关于事件驱动的编程是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!