5 Types of IO models
Five types of IO models under Linux
(1) Blocking I/O: doing nothing, causing the application to block, waiting for data to be ready, if the data is not ready, blocking, etc. data is ready to be copied from the kernel to the user space
(2) Non-blocking I/O: Set a socket interface to non-blocking, tell the kernel, when the requested IO cannot be completed, do not sleep the process, but return an error, so the IO operation function will continuously test whether the data is ready, if not ready, continue testing until ready
(3) I/O multiplexing (select Epoll): Select or Epoll causes the process to block, but unlike blocking IO, these two functions can block multiple IO operations at the same time, while multiple read operations, multiple write IO functions are detected, until there is data readable or writable
(4) Signal-driven I/O (SIGIO):
(5) asynchronous I/O (POSIX): Only initiate IO events
Summary: The first four kinds are called synchronous IO
Common:
Once the data is ready, it must be self-blocking read/write
Different points:
Wait in a different way
The fifth one is asynchronous IO
Do not participate in wait and data relocation, only initiate IO action
Synchronization of semaphores is not the same as here
The order of previous synchronizations when accessing critical resources in multi-process multithreading
The difference between synchronous IO and asynchronous IO: when data access is blocked
The difference between blocking IO and non-blocking IO: whether an application call returns immediately
Synchronous vs. asynchronous
(1) Synchronous and asynchronous attention is the message communication mechanism, so-called synchronization is the time to make a call, the call does not return until the result is not obtained, but once the call returns, the return value is obtained, in other words, the caller actively waits for the result of the call
For example, normal b/S mode (synchronous): Submit Request , wait for server processing, processing completed return this period the client browser can not do anything
(2) Async occurs after a call occurs, the caller does not immediately get the result of the call, the part that actually handles the call is completed, and the caller is processed through state, notification, and callback
Blocking and non-blocking (primarily for server-side)
Blocking call: means that the current thread hangs before the call results are returned, and the calling thread returns only after the result is obtained.
Non-blocking invocation: means that the result of the call cannot be obtained immediately, and the call does not block the current thread.
Synchronous vs. asynchronous (primarily for clients)
Synchronization: The client invokes a feature that is in death state before the function is ended
Async: The client invokes a feature that does not know the result of the feature, and will proactively notify the client when the function has results
Five types of IO models under Linux