The duration of this section needs to be controlled 15 Within minutes
To better understand IO Model , We need to review in advance : Sync 、 asynchronous 、 Blocking 、 Non blocking
Sync (synchronous) IO And asynchronous (asynchronous) IO, Blocking (blocking) IO And non blocking (non-blocking)IO What are the differences , What's the difference ? In fact, different people may give different answers to this question , such as wiki, I think asynchronous IO and non-blocking IO It's a thing . This is actually because different people have different knowledge backgrounds , And in the context of the discussion (context) It's not the same . therefore , In order to better answer this question , Let me first limit the context of this article .
The background of this paper is Linux In the environment network IO. The most important reference of this article is Richard Stevens Of “UNIX Network Programming Volume 1, Third Edition: The Sockets Networking ”,6.2 section “I/O Models ”,Stevens In this section, various kinds of IO Characteristics and differences , If English is good enough , Direct reading is recommended .Stevens The style of writing is famous for its simplicity , So don't worry about not understanding . The flow chart in this paper is also taken from the reference .
Stevens There are five kinds of comparison in the article IO Model:
* blocking IO
* nonblocking IO
* IO multiplexing
* signal driven IO
* asynchronous IO
from signal driven IO( Signal driven IO) Not commonly used in practice , So we mainly introduce the other four IO Model.
Say it again IO The objects and steps involved in the occurrence . For one network IO ( Here we have read give an example ), It involves two system objects , One is to call this IO Of process (or thread), The other is the system kernel (kernel). When one read When the operation occurs , The operation will go through two stages :
1) Wait for the data to be ready (Waiting for the data to be ready)
2) Copy data from the kernel into the process (Copying the data from the kernel to the process)
It's important to remember these two points , Because of these IO The difference between models is that there are different situations in the two stages .