举一个例子来说明。
父亲叫儿子去请叔叔来下棋,儿子需要开车去叔叔家。
同步:父亲在家什么事也不能做,在家等着。叔叔回来了儿子敲门通知父亲。
异步:父亲有一大堆其它事情要忙,打发儿子完儿子后接着忙一大堆其它的事情,等儿子回来了敲门通知父亲。
上面的同步和异步都使用到了非阻塞操作。
同步和异步的区别就在于:同步必须等到操作的结果,否则其它事都做不了;异步体现在操作发起后不用等待的结果,接着做其它事情,等操作结果出来了会受到通知并作相应处理。
Douglas博士的解释如下:
AIO is "asynchronous I/O", i.e., the operation is invoked asynchronously and control returns to the client while the OS kernel processes the I/O request.?When the operation completes there is some mechanism for the client to retrieve the results.
Non-blocking I/O tries an operation (such as a read() or write()) and if it the operation would block (e.g., due to flow control on a TCP connection or due to lack of data in a socket), the call returns -1 and sets errno to EWOULDBLOCK.
posted on 2009-09-11 00:32
clj 阅读(1393)
评论(0) 编辑 收藏 引用