CreateIoCompletionPort 的第四个参数 NumberOfConcurrentThreads 它告诉系统一个完成端口上同时允许运行的线程最大数。在默认情况下,所开线程数和CPU数量相同,但经验给我们一个公式:
线程数 = CPU数 * 2 + 2
但我看了别人写的 IOCP 的程序以及很多例子都把 NumberOfConcurrentThreads 设置为 0;
而别外开了 ( CPU数 * 2 + 2 ) 个 accept 线程?请问这是为什么?

解决方案 »

  1.   

    NumberOfConcurrentThreads 设置为 0NumberOfConcurrentThreads 
    [in] Maximum number of threads that the operating system can allow to concurrently process I/O completion packets for the I/O completion port. This parameter is ignored if the ExistingCompletionPort parameter is not NULL.
    If this parameter is zero, the system allows as many concurrently running threads as there are processors in the system. 
      

  2.   

    E 文不是很好, 没能理解其中的意思, 设置为0表示系统所允许最多的线程? 为什么不设置为  ( CPU数 * 2 + 2 )
      

  3.   

    已经说的很清楚了啊
    第一此使用CreateIoCompletionPort创建iocp口,这个参数发挥作用,之后调用把其他io handle绑定到这个iocp口上的调用此参数被忽略。如果参数为0,相当于指定一个和你机器cpu数量的值。