IO Completion Ports vs. Thread Pool API

I had the problem described here and they suggested that I use the I / O completion ports or the thread pool.

I completed the I / O by calling PostQueuedCompletionStatusto set the task and GetQueuedCompletionStatusto complete the next task. I use the I / O completion port as a multi-threaded / multi-threaded thread-safe FIFO container without explicit locks. This forces me to completely control the threads, because I may need to stop the process for a long time and report it. In addition, the GetQueuedCompletionStatuscalling thread waits if there is no task specified.

Besides completion, the thread pool satisfies my needs: my tasks are completed in less than a millisecond, but there are many of them. Also invoking QueueUserWorkItemand allowing the OS to perform synchronization and execution is easier.

Are there differences between the two performance approaches? Any comments on my implementation?

+3
source share
4 answers

Termination ports are designed to prevent unnecessary context switching. When your thread calling GetQueuedCompletionStatus processes the work item, it can go back to GetQueuedCompletionStatus to continue working with the current processor time interval.

@Jonathan - , . async ( Begin/End * Async), ( ). , , , , , .

: GetQueuedCompletionStatus, - , -.

+2

IO (IOCP) threadpool / IO, WinAPI ( QueueUserWorkItem) Microsoft , , IO.

, , FIFO, IO. , , , , . , , API , .

EDIT: ( , ), threadpool WaitForSingleObject (, , MultipleObjects ) SetEvent. WinAPI threadpool - , , Microsoft .

+2

- X, GetQueuedCompletionStatus(), X, (, ), , . AFAIU, .

, TerminateThread()! CRITICAL_SECTION. , , , , . , .

+1

QueueUserWorkItem IOCompletionPorts - QueueUserWorkItem - . , QueueUserWorkItem IOCompletionPorts ( , ).

- QueueUserWorkItem ( ) . , , : (, ), , .

, QueueUserWorkItem , , , , , .

-1

Source: https://habr.com/ru/post/1781662/


All Articles