1

In the book "WinSock Programming Fundamental: A Compilation", there is this diagram for IOCP:

enter image description here

I understand that the completion notifications arrive at the completion port, and that the four queued threads call GetQueuedCompletionStatus() to get a completion packet. But what does the other two worker threads shown below the completion port do, is it that these threads also call GetQueuedCompletionStatus() but they have already received a completion packet, and they are now processing it?

  • 2
    I believe so, yes. The 'active' threads are handing buffers etc, and the 'inactive' threads are still stuck on GetQueuedCompletionStatus(), waiting for something to do, or being held because of the overall cap on running threads that is a feature of IOCP. – Martin James Feb 23 '15 at 15:52
  • Off-topic: The entire front page (50+ questions) of the C++ section is SSL, IOCP, and Sockets.. What is this? Is everyone on the planet doing high performance sockets at the exact same time? Lol. :O Pretty cool to see though. – Brandon Feb 23 '15 at 18:50
  • I've just taken a quick look at that book you mention. Personally I'd get a proper text on the subject, Network Programming for Microsoft Windows is still the best for getting an understanding of how it all works even though it's a bit dated. Once you understand how IOCPs operate you can update your knowledge using MSDN and online resources. – Len Holgate Feb 24 '15 at 09:00

1 Answers1

5

As Martin James says in his comment; The Queued Threads and the Worker Threads are all threads that have called GetQueuedCompletionStatus(). The threads designated as Worker Threads have been given a completion to process and are doing so. The threads designated as Queued Threads are waiting, either for more completions or are blocked by the IOCP due to the concurrency value that it was created with. If the later then they will wait for one of the Worker Threads to block on an API that the IOCP API knows about. If one Worker Threads completes processing the current completion that it has then it will go to the front of the queue of inactive threads (thus allowing the IOCP to provide its LIFO functionality which keeps active threads in play and thus helps to reduce context switches and memory faults).

Len Holgate
  • 21,282
  • 4
  • 45
  • 92