Wednesday, September 1, 2010

Using ReadFileEx

Tip - The IOCompletion routine will be called only when the read operation is complete and the calling thread is in an alertable wait state.

Details - Applications uses the ReadFileEx/ WriteFileEx API for reading/writing data to disk in asynchronous mode. We have to give a callback function pointer as the 5th parameter of ReadFileEx API. This call back function (IOCompletion routine) will be called only when the read/write operation is complete and the calling thread is in an alertable wait state.
The alertable wait state means, the calling thread must wait using MsgWaitForMultipleObjectsEx or WaitForSingleObjectEx or WaitForMultipleObjectsEx or SleepEx APIs.

Reference
http://msdn.microsoft.com/en-us/library/aa365468%28VS.85%29.aspx

Posted by - Aneesh Valeri

1 comment:

  1. Since the callback functions are queued as APC(Asynchronous Procedure Call) we should take immense care for calling the alertable wait functions on the same thread on which the asynchronous file IO function was called.

    In short, the thread that calls an alertable wait function must be the same thread that called the file I/O function.

    ReplyDelete