RocketR
RocketR

Reputation: 3776

Number of Concurrent Threads in CreateIoCompletionPort

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

NumberOfConcurrentThreads [in]

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

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?

Upvotes: 4

Views: 1456

Answers (1)

Alan Stokes
Alan Stokes

Reputation: 18974

See 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.

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

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.

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

Upvotes: 7

Related Questions