IO-同步 异步 阻塞 非阻塞

定义:

   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;

常见IO模型:

    blocking IO:笨懒,一直躺着等结果
    nonblocking IO:拼命的工人,不停的跑过来询问事情进程。特征是轮询
    signal driven IO:理性的科学家,同时安排多个事情,事情处理完后取结果。特征是事务驱动
    asynchronous IO:富人,不需要自己动手,把事情委托手下,手下办完了打个电话汇报。特征是回调

实例对比:

对于一个network IO (这里我们以read举例),它会涉及到两个系统对象,一个是调用这个IO的process (or thread),另一个就是系统内核(kernel)。当一个read操作发生时,它会经历两个阶段:
 1 等待数据准备 (Waiting for the data to be ready)
 2 将数据从内核拷贝到进程中 (Copying the data from the kernel to the process)
blocking IO

 

nonblocking IO:

 

signal driven IO

asynchronous IO

比较各种io模型:

可以认为前3个io模型都属于同步io,因为进程其实还是被block了,唯独第4个io进程完全没有被lock。

 

posted @ 2015-03-23 15:54  xiongjianjun  阅读(75)  评论(0编辑  收藏  举报