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?
Asked
Active
Viewed 288 times
1

Tom
- 1,344
- 9
- 27
-
You can either create the completion port yourself and use `CreateThread` or equivalent, or you can let the thread pool take care of it all: [CreateThreadpoolIo](https://msdn.microsoft.com/en-us/library/ms682464%28v=vs.85%29.aspx). – Harry Johnston Mar 03 '15 at 20:50
-
@Harry Johnston So if I want to create 4 threads that waits on the completion port, I would just call `CreateThread()` 4 times? Also, I would guess that I should use `_beginthreadex()` and not `CreateThread()`, correct? – Tom Mar 03 '15 at 21:38
-
1(1) yes. (2) It doesn't really matter any more except as a matter of style. Use whichever you prefer. – Harry Johnston Mar 03 '15 at 21:39
-
Actually it's far more than a matter of style. You MUST use `_beginthreaex()` if you use the c runtime otherwise key library components will not be initialised correctly until they are first used and this may cause problems in low memory situations (see the docs for `CreateThread()`). – Len Holgate Mar 06 '15 at 12:26
1 Answers
1
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.

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