Asynchronous Procedure Calls

An asynchronous procedure call (APC) is a function that executes asynchronously in the context of a particular thread.

QueueUserAPC

A thread enters an alertable state when it calls the SleepEx, SignalObjectAndWait, MsgWaitForMultipleObjectsEx, WaitForMultipleObjectsEx, or WaitForSingleObjectEx function.

The ReadFileEx, SetWaitableTimer, SetWaitableTimerEx, and WriteFileEx functions are implemented using an APC as the completion notification callback mechanism.

If you are using a thread pool, note that APCs do not work as well as other signaling mechanisms because the system controls the lifetime of thread pool threads, so it is possible for a thread to be terminated before the notification is delivered. Instead of using an APC-based signaling mechanism such as the pfnCompletionRoutine parameter of SetWaitableTimer or SetWaitableTimerEx, use a waitable object such as a timer created with CreateThreadpoolTimer.

 

1) With synchronous I/O, the thread builds the IRP, sends it to the device stack, and waits in the kernel for the IRP to complete.

2) With asynchronous I/O, the thread builds the IRP and sends it to the device stack. The stack might complete the IRP immediately, or it might return a pending status indicating that the request is in progress.In the meantime, the thread can continue to perform other tasks while the device stack continues to process the IRP.

Synchronization Objects

Synchronization Objects
Event Notifies one or more waiting threads that an event has occurred.
Mutex Can be owned by only one thread at a time, enabling threads to coordinate mutually exclusive access to a shared resource.
Semaphore Maintains a count between zero and some maximum value, limiting the number of threads that are simultaneously accessing a shared resource.
Waitable timer Notifies one or more waiting threads that a specified time has arrived.
Change notification Created by the FindFirstChangeNotification function, its state is set to signaled when a specified type of change occurs within a specified directory or directory tree.
Console input Created when a console is create.The handle to console input is returned by the CreateFile function when CONIN$ is specified, or by the GetStdHandle function. Its state is set to signaled when there is unread input in the console's input buffer, and set to nonsignaled when the input buffer is empty.
Job  
Memory resource notification  
Process  
Thread  

 

参考资料

Asynchronous Procedure Calls

Synchronization Objects

posted @ 2020-07-23 15:06  anyboo  阅读(162)  评论(0编辑  收藏  举报