Overview of Windows Asynchronous I/O
There are three techniques for achieving asynchronous I/O in Windows.
- Multithreaded I/O.
Each thread within a process or set of processes performs normal synchronous I/O, but other threads can continue execution. - Overlapped I/O.
A thread continues execution after issuing a read, write, or other I/O operation. When the thread requires the I/O results before continuing, it waits on either the handle or a specified event. Windows 9x supports overlapped I/O only for serial devices such as named pipes. - Completion routines (or extended I/O).
The system invokes a specified completion routine within the thread when the I/O operation completes. Windows 9x does not support extended I/O for disk files.
The threaded server in Chapter 11 uses multithreaded I/O on named pipes. grepMT (Program 7-1) manages concurrent I/O to several files. Thus, we have already written programs that perform multithreaded I/O to achieve a form of asynchronous I/O.Overlapped I/O is the subject of the next section, and the examples implement file conversion (ASCII to Unicode) using this technique in order to illustrate sequential file processing. The example is a modification of Program 2-4. Following overlapped I/O, extended I/O with completion routines is explained.Note:
Overlapped and extended I/O can be complex, seldom yield performance benefits, may even harm performance, and, for file I/O, work only on Windows NT. Threads overcome these problems, so some readers might wish to skip ahead to the sections on waitable timers and I/O completion ports, referring back as necessary. On the other hand, you will find asynchronous I/O concepts in both old and very new technology, so it can be worthwhile to learn the techniques. For example, COM on NT5 supports the asynchronous method call, and many readers who are using or will be using COM may find this feature useful. Also, the asynchronous procedure call operation (Chapter 10) is very similar to extended I/O, and, while my personal preference is to use threads, others like to use this mechanism.
