Search code examples
c++socketswinapinetwork-programmingiocp

How to create multiple threads for the completion port?


Multiple threads can dequeue completion packets from a single completion port using the GetQueuedCompletionStatus() function. Is there a special function that creates these threads? Or I simply use for example CreateThread() or _beginthreadex() and create as much threads as I need?


Solution

  • There is nothing special about a thread that calls GetQueuedCompletionStatus() on a given IOCP. Any thread can do it. Therefore you can create your "I/O threads" using the usual thread creation functions. In general it's best to use _beginthreadex() unless you're writing code for platforms that do not support it OR you are not linking with the CRT.