The five I/O models
- blocking I/O
- nonblocking I/O
- I/O multiplexing (select,poll,epoll)
- signal driven I/O (SIGIO)
- asynchronous I/O (the POSIX aio_functions)
The two distinct phases for an input operation:
As we show in all the examples in this section, there are normally two distinct phases for an input operation:
- Waiting for the data to be ready
- Copying the data from the kernel to the process
For an input operation on a socket, the first step normally involves waiting for data to arrive on the network. When the packet arrives, it is copied into a buffer within the kernel. The second step is copying this data from the kernel’s buffer into our application buffer.
Comparison of the I/O Models
It shows that the main
difference between the first four models is the first phase, as the second phase in the
first four models is the same: the process is blocked in a call to recvfrom while the
data is copied from the kernel to the caller’s buffer. Asynchronous I/O, however,
handles both phases and is different from the first four.
Synchronous I/O versus Asynchronous I/O
POSIX defines these two terms as follows:
- A synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes.
- An asynchronous I/O operation does not cause the requesting process to be blocked.
Using these definitions, the first four I/O models—blocking, nonblocking, I/O multiplexing, and
signal-driven I/O—are all synchronous because the actual I/O operation (recvfrom) blocks the process. Only the asynchronous I/O model matches the asynchronous I/O definition.
近期评论