自定义线程池中的 IOCP [英] IOCP in custom thread pool

查看:33
本文介绍了自定义线程池中的 IOCP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Internet 上搜索自定义线程池实现.我找到了一个使用 IOCP 的实现.我想知道使用它们有什么好处?他们是否提供窃取作品之类的东西,我真的可以找到答案...

I'm currently searching the internet for a custom thread pool implementation. I found an implementation which uses IOCP's. I'm wondering what the benefit is, of using them? Do they provide work stealing, or something like that, I could really find an answer...

推荐答案

IOCP = "IO 完成端口".它是 Windows 操作系统中内置的内核对象,可为您提供管理多线程异步 IO 的智能方法.

IOCP = "IO Completion Port". It is a kernel object built into the Windows OS that is there to give you an intelligent way to manage multithreaded asynchronous IO.

用非常简单(有点过于简化)的术语来说,您将您想要完成的 IO 作业告诉 IOCP.它将异步执行它们并维护每个作业的结果队列.您将作业告知 IOCP 的调用会立即返回(在 IO 发生时它不会阻塞).您将返回一个概念上类似于 .NET IAsyncResult 的对象......它允许您选择阻止,或者您可以提供回调,或者您可以定期轮询以查看作业是否完成.

In very simplistic (and a little over-simplified) terms, you tell the IOCP about the IO jobs you want done. It will perform them asynchronously and maintain a queue of the results of each of those jobs. Your call to tell the IOCP about the job returns immediately (it does not block while the IO happens). You are returned an object that is conceptually like the .NET IAsyncResult ... it lets you block if you choose to, or you can provide a callback, or you can periodically poll to see if the job is complete.

在执行这些工作时,IOCP 使用线程池.线程池尝试将线程数限制为处理器数或更少(这是可配置的,但意图和默认值是将其限制为处理器数).但是,IOCP 为以下事实做出了规定:有时,这些线程上的任务可能会阻塞.Asycn IO 任务不会阻塞,但您可能已经为其提供了某种其他类型的任务.所以,你可以给 IOCP 另一个数字......这是一个高于通常最大值"的线程数,由于其他线程之一被阻塞,IOCP 被允许上升.目标是使实际执行某事(即未阻塞)的线程达到通常的最大值".如果发生这种情况,那么在一段时间内 IOCP 将使用比通常最大值更多的线程,但它会拒绝创建任何新线程,直到它可以回到通常的最大值".

While doing those jobs, the IOCP uses a thread pool. The thread pool tries to limit the number of threads to the number of processors or less (that's configurable, but the intent and the default is to limit it to the number of processors). However, the IOCP makes a provision for the fact that sometimes, the tasks on these threads might block. Asycn IO tasks won't block, but you might have provided it some other kind of task. So, you can give the IOCP another number ... this is a number of threads above the "usual maximum", which the IOCP is allowed to go up to due to one of the other threads being blocked. The goal is to have up to the "usual maximum" of threads that are actually doing something (ie, not blocked). If this happens, then for a while the IOCP will be using more threads than the usual max, but it will refuse to make any new threads until it can get back down to the "usual max".

这是一个简短的总结,只是概念性的,正如我所说,在某些方面过于简化了.但它应该给你一般的想法.Jeffrey Richter 关于 Windows 操作系统的书籍详细介绍了这一点(但这些书籍现已绝版).你会发现这些书被使用了,而且它们的使用成本实际上比原来的要高.我认为高级 Windows"是您想要的书名,但该书的更新版本可能有不同的书名.

This is a brief summary, conceptual only, and as I said, over-simplified in some ways. But it should give you the general idea. Jeffrey Richter's books on the Windows OS cover this in detail (but these books are out of print now). You can find these books used, and they actually cost more used than they did originally. I think "Advanced Windows" is the title you'd want, but there may have been an updated version of the book with a different title.

这篇关于自定义线程池中的 IOCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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