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.
<UNIX网络编程>> 第三版 6.2节
这段是关于IO同步异步的描述,书中说到:
一个同步的IO操作使得请求进程一直被阻塞,直到IO操作完成;
一个异步的IO操作不会导致请求进程被阻塞.
说说关于腾讯面试官问的epoll到底是同步的还是异步的?
你认为呢?我们该如何理解从哪个角度哪个层面来理解提问者提出的“同步异步”问题呢?
也许我们应该问一问面试官,请他提供一个具体的讨论背景.或者我们可以直接从不同维度
给出相对较全面的答案.
IO层面
消息处理层面
从IO层面来看,epoll绝对是同步的;
从消息处理层面来看,epoll是异步的.
作为提问者,也许我们可以提出这样一个含糊的问题,但是作为答题者和一个研究者,也许我们需要
更加全面的了解这其中的方方面面,从不同角度来思考提问者给我们抛来的问题.