Does GetQueuedCompletionStatusEx performs load balancing when multiple threads are waiting on the same IOCP?

57 views Asked by At

Let's assume 4 threads on a 4 core CPU computer wait on the same IOCP using the regular GetQueuedCompletionStatus function. When 4 I/O operations complete simultaneously, each of the 4 threads get 1 completion packet and then all the 4 threads can process their packet simultaneously.

Does the same still applies when GetQueuedCompletionStatusEx (which can retrieve multiple completions simultaneously) is used? What if 4 threads wait for packets using the Ex version? Will each of the threads get only 1 completion packet just like using the regular API? Or will one thread get all the 4 completion packets?

I'm wondering because if it does the latter then it's pretty much defeats the idea of processing completion packets in parallel on multiple threads.

1

There are 1 answers

0
RbMm On

What if 4 threads wait for packets using the Ex version? Will each of the threads get only 1 completion packet just like using the regular API? Or will one thread get all the 4 completion packets?

There is no API that would insert several packets at once. always inserted only 1 packet. as result always some thread get only 1 packet, no matter which api and with which parameters used.

from another side, if several (m) packets already in queue, and Ex version is called, for remove up to n packets - the min(m,n) packets will be removed by this thread. again impossible that more than one thread begin wait at once. always only 1 thread access port. if several packets exist in queue at this time - thread can remove several packets, or begin wait if no packets (or too many threads already active on queue)

so by fact question no big sense at all.