在 Java 或 C# 或其他一些语言中,有非阻塞 IO 设施,例如用于套接字.
In Java or C# or some other languages, there are non-blocking IO facilities, e.g., for sockets.
所以我可以将我的回调函数提供给非阻塞 IO,一旦非阻塞 IO 接收到任何东西,它就会调用我的回调.
So I can give my callback functions to the non-blocking IO and once the non-blocking IO receives anything, it will call my callbacks.
我想知道它们是如何实现的.如果我在幕后创建非阻塞 IO,Java 或 C# 是否只是为它们创建后台线程?或者底层操作系统对它们有原生支持?
I am wondering how they are implemented. If I create non-blocking IO, behind the scene, does Java or C# just create background threads for them? or the OS underlying has native support for them?
推荐答案在 Windows 上,底层操作系统支持非阻塞 I/O,Microsoft 的 CLR 就利用了这一点.其他 CLR 实现(单声道)可能也是如此,但我不确定.在 Microsoft CLR 上执行异步 I/O 时,挂起的异步 I/O 操作与等待这些 I/O 操作完成的线程(或至少是托管线程)之间没有一对一的相关性.
On Windows there is underlying OS support for non-blocking I/O, and Microsoft's CLR takes advantage of that. Other CLR implementations (mono) probably do as well, but I don't know for sure. When performing async I/O on the Microsoft CLR there is not a 1-to-1 correlation between pending async I/O operations and threads (or at least managed threads) waiting for those I/O operations to complete.
参见 msdn.microsoft/en-us/library/windows/desktop/aa365683(v=vs.85).aspx 有关 Win32 层详细信息的一些详细信息.还有关于 I/O 完成端口的信息:/msdn.microsoft/en-us/library/aa365198(VS.85).aspx
See msdn.microsoft/en-us/library/windows/desktop/aa365683(v=vs.85).aspx for some details on the Win32-layer details. Also the information on I/O completion ports here: msdn.microsoft/en-us/library/aa365198(VS.85).aspx
我的理解是:
以上注意事项:
我确定我弄错了一部分,但我相信它的整体要点是正确的.埃里克或其他人可以进来纠正我的错误.
I am sure I got part of this wrong, but I believe the overall gist of it is correct. Eric or someone can come in and correct me where I'm off.
在 .NET 中有多个 I/O 完成端口线程.我不知道异步 I/O 请求是如何在各种 I/O 完成端口之间分配的.这可能是操作系统功能(其中 I/O 可能会在应用程序打开的任何端口上返回).
In .NET there are multiple I/O completion port threads. I have no idea how async I/O requests are allocated amongst the various I/O completion ports. This may be an operating system feature (wherein I/O may come back on any port that the application has open).
对于 Java,我确信它取决于 JVM 实现和特定的操作系统.我对它的了解还不够深入,无法对此进行推测.
For Java I am sure it depends on the JVM implementation and the particular OS. I don't know it nearly well enough to speculate beyond that.
历史更新,更多细节这里
更多推荐
非阻塞 IO 是如何实现的?
发布评论