What happens if there are no IO threads to handle async result?

I'm wondering what happens when there are no IO threads to handle the result of an async call.

Say you make an async web request (in a server application so all async code is handeled by the thread pool). The OS will signal when there is a result for you and when it does you'll need an IO thread to read the bytes from the socket. If there are no IO threads available because that are all in use (all meaning up to the max set by the thread pool) what happens? Is there a queue where the signal can wait until there is a thread available? Or does the signal just go unheard? If the latter happens, what happens to the code waiting on the await?


Unless you've restricted the thread pool, it will create new I/O threads as necessary. The signal waits in a queue-like structure called an I/O Completion Port (IOCP) until it is retrieved; signals are not lost.


Let's go back to earlier times, when OS use to preliminary and did not have much scope of concurrency , then if you open up multiple applications, which needs IO like Excel, Word, Pdf, Ppt , system will appear to be hung and unresponsive, since it cannot deal with all of them together, but if you stop queuing up more request, and system doesn't crash, then you will see all of them get their chance and they get active again.

This is a typical use case of IO requests been queued up waiting for being processed, none of them is lost until and unless the system crash, which doesn't happen nowadays that often, due to robustness of its implementation, remember Blue screen of death, which can still happen and that's the only point when IO requests will be lost.

In fact the essence of Threading in Windows is to introduce robustness even before concurrency, so that nothing that is queued up for processing is lost. At no point of time it will exceed its limit to create more than required number of threads

链接地址: http://www.djcxy.com/p/53256.html

上一篇: 如何:在Kotlin中触发并忘记异步协程

下一篇: 如果没有IO线程来处理异步结果,会发生什么情况?