Synchronous IO, asynchronous IO understanding

1. What is the IO?

 All the time there is no access and read (data is stored on a physical medium, such as a register, cache, memory, disk, network card, etc.) of data, these are referred to IO operations in a computer.

2. blocking IO

 

  (1) When a user initiates a thread IO request, a system call (system call) to the kernel (Kernel) perform IO operations

   (2) At this point the user thread blocks, waiting for the kernel data is ready

   (3) the kernel data will be ready to copy data from kernel space to user space, and returned to the user thread end blocking.

3. Non-blocking IO

  

   (1)  initiated by a user request thread IO, system calls to the kernel to perform IO operations

      (2) At this point if the kernel is not ready to return data will direct error, and does not block the user thread, the thread can repeat users initiate IO requests

    (3) When a user initiates a request and kernel threads have data ready, data is copied from kernel space to user space (this process is the need to block user thread), returned to the user

4. multiplexing IO

  

  (1) User system call (kernel will be responsible for monitoring all select the socket) after thread calls select, then the user thread is blocked

   (2) When the kernel will return the data is ready, and notifies the user threads a read operation, this time to copy data to the kernel and user space returns

The blocking and non-blocking IO IO?

    Blocking IO: IO operation initiated by the user thread, followed by an IO operation by the kernel threads, kernel threads in blocking IO and does not return immediately, but waiting for data to be copied to the memory space only to return, during which the user thread is blocked .

 Non-blocking IO: IO and obstructive different kernel thread returns immediately after an IO operation, if the result is error, the user can re-initiate the request thread is not blocked, the kernel once the data is ready and the user initiated the IO thread then the request to copy data to the user space.

  We look at the above graph that the IO operation is broadly divided into two parts:

  (1) user threads initiate IO requests, the kernel is not ready data

  (2) user threads initiate IO requests, the kernel data in order to be ready

    We can see by comparing the two figures flow, (2) blocking this process in non-blocking IO and IO is the same process except that (1) this step. Difference between blocking and non-blocking IO IO is therefore to kernel threads are returned immediately result in the implementation of IO operation, if immediately returned

    Return, compared with non-blocking IO, otherwise it is blocking IO.

6. synchronous and asynchronous IO?

 Asynchronous IO: IO operation initiated by the user thread, you can do other things immediately, on the other hand, for kernel threads when it receives an asynchronous read will return immediately and will not cause obstruction to the user thread. When the data is ready after the kernel will copy data from kernel space to a user space, the kernel sends a signal to the user the user has completed the IO operation.

    Synchronous IO: IO synchronization key is whether the user thread is blocked when you actually read the data (that is, (2) the steps mentioned above). Although non-blocking IO returns the user initiates a request immediately, but when the kernel is ready data, any course require the user to initiate a request thread will copy data from kernel space to user space, and therefore belong to the non-blocking IO synchronous IO.

 

   

    

   

   

 

Guess you like

Origin www.cnblogs.com/liwangcai/p/11823025.html