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.
PostQueuedCompletionStatus
GetQueuedCompletionStatus
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.
QueueUserWorkItem
Are there differences between the two performance approaches? Any comments on my implementation?
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, - , -.
IO (IOCP) threadpool / IO, WinAPI ( QueueUserWorkItem) Microsoft , , IO.
, , FIFO, IO. , , , , . , , API , .
EDIT: ( , ), threadpool WaitForSingleObject (, , MultipleObjects ) SetEvent. WinAPI threadpool - , , Microsoft .
- X, GetQueuedCompletionStatus(), X, (, ), , . AFAIU, .
, TerminateThread()! CRITICAL_SECTION. , , , , . , .
QueueUserWorkItem IOCompletionPorts - QueueUserWorkItem - . , QueueUserWorkItem IOCompletionPorts ( , ).
- QueueUserWorkItem ( ) . , , : (, ), , .
, QueueUserWorkItem , , , , , .
Source: https://habr.com/ru/post/1781662/More articles:WCF with WSHttpBinding, Message Security, clientCredentialType = "UserName" Cerificate SelfHosted Issue - deploymentHow to properly bind datacontext RelativeSource in WPF? - wpfGood Sites to Get Graphics for iPhone Apps - iosSalesForce: может ли она отображать внешнюю страницу/может ли она публиковаться в другой реализации SF - salesforceC # How to get the relative path to a file located in a folder with a large parent? - c #Admob Error In iPhone - iphoneCalling a Java Servlet from C # - javaWaiting for win32 threads - c ++C # - count and list of locations of file hard links - c #ASP.NET 4.0 на Windows Server 2003 64-разрядный - asp.netAll Articles