Performing asynchronous I/O requires kernel support at the very lowest layers. POSIX 1003.1-2003 defines the aio interfaces, which Linux fortunately implements. The aio library provides a family of functions for submitting asynchronous I/O and receiving notification upon its completion: #include <aio.h> /* asynchronous I/O control block */ /* internal, private members follow... */ int aio_read (struct aiocb *aiocbp); Thread-based asynchronous I/O Linux only supports aio on files opened with the O_DIRECT flag. To perform asynchronous I/O on regular files opened without O_DIRECT, we have to look inward, toward a solution of our own. Without kernel support, we can only hope to approximate asynchronous I/O, giving results similar to the real thing. First, let’s look at why an application developer would want asynchronous I/O:
The first point is a matter of performance. If I/O operations never block, the overhead of I/O reaches zero, and a process need not be I/O-bound. The second point is a matter of procedure, simply a different method of handling I/O. The most common way to reach these goals is with threads (scheduling matters are discussed thoroughly in Chapters 5 and 6). This approach involves the following programming tasks:
This provides similar behavior to POSIX’s aio interfaces, albeit with the greater overhead of thread management. Please check back next week for the continuation of this article.
blog comments powered by Disqus |