CreateIoCompletionPort 中的并发线程数 [英] Number of Concurrent Threads in CreateIoCompletionPort

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

问题描述

CreateIoCompletionPort 的 MSDN 页面上 这个函数的最后一个参数有一个非常简短的描述:

On MSDN page for CreateIoCompletionPort there's a very short description for the last parameter of this function:

NumberOfConcurrentThreads [输入]

操作系统允许的最大线程数并发处理 I/O 完成数据包用于 I/O 完成端口...

The maximum number of threads that the operating system can allow to concurrently process I/O completion packets for the I/O completion port...

具体是什么意思?我对并发"这个词感到困惑——这听起来像是不同的线程处理相同的 I/O 数据包?而且,如果我从多于允许的线程数调用 GetQueuedCompletionStatus 会发生什么?

What exactly does it mean? I'm confused with the word 'concurrently' - this sounds like different threads process the same I/O packet? And also, what happens if I call GetQueuedCompletionStatus from more threads than allowed?

推荐答案

参见 http://msdn.microsoft.com/en-us/library/aa365198(v=VS.85).aspx

当与关联的可运行线程总数完成端口达到并发值,系统阻塞执行与该完成相关的任何后续线程端口,直到可运行线程的数量低于并发价值.

When the total number of runnable threads associated with the completion port reaches the concurrency value, the system blocks the execution of any subsequent threads associated with that completion port until the number of runnable threads drops below the concurrency value.

其中并发值"是 NumberOfConcurrentThreads.(还有更多好东西.)

Where "concurrency value" is NumberOfConcurrentThreads. (And there's lots more good stuff.)

除非您正在做一些不寻常的事情,否则 0 似乎是一个很好的传递值,其中并发值是内核数.然后,假设有足够的可用工作,您可以让每个核心从队列中提取完成结果,而无需阻塞或上下文切换.

Unless you're doing something a bit unusual, 0 seems to be a good value to pass, where the concurrency value is the number of cores. Then you can have every core pulling completion results off the queue without ever blocking or context switching, assuming there is enough work available.

任何调用 GetQueuedCompletionStatus 的额外线程都会阻塞,即使有可用的完成.

Any extra threads that make calls to GetQueuedCompletionStatus will block, even if there are completions available.

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

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