APC异步过程调用

来源:互联网 发布:知君何事泪纵横中的君 编辑:程序博客网 时间:2024/04/29 15:00

转自http://blog.csdn.net/hurtmanzc/article/details/1687000

这是MSDN官网详细的介绍:http://msdn.microsoft.com/en-us/library/windows/desktop/ms681951(v=vs.85).aspx

   APC : asynchronous procdure call 异步过程调用
    Alertable IO(告警IO)提供了更有效的异步通知形式。ReadFileEx / WriteFileEx在发出IO请求的同时,
    提供一个回调函数(APC过程),当IO请求完成后,
一旦线程进入可告警状态,回调函数将会执行。
    以下五个函数能够使线程进入告警状态:
    SleepEx
    WaitForSingleObjectEx
    WaitForMultipleObjectsEx
    SignalObjectAndWait
    MsgWaitForMultipleObjectsEx
    线程进入告警状态时,内核将会检查线程的APC队列,如果队列中有APC,将会按FIFO方式依次执行。
    如果队列为空,线程将会挂起等待事件对象。以后的某个时刻,一旦APC进入队列,线程将会被唤醒
    执行APC,同时等待函数返回WAIT_IO_COMPLETION。
    QueueUserAPC可以用来人为投递APC,只要目标线程处于告警状态时,APC就能够得到执行。
    使用告警IO的主要缺点是发出IO请求的线程也必须是处理结果的线程,如果一个线程退出时还有
    未完成的IO请求,那么应用程序将永远丢失IO完成通知。

    PS:Each thread has its own APC queue. The queuing of an APC is a request for the thread to call the APC function. The operating system issues a software interrupt to direct the thread to call the APC function.