Io mode-synchronous (blocking, non-blocking), asynchronous

Source: Internet
Author: User
Tags epoll

Many people put synchronization, Asynchronization, blocking, and non-blocking together for discussion, which is often difficult to differentiate.


Let's take a root look at these concepts.


First, asynchronous synchronization is relative to synchronization, and blocking and non-blocking are involved in synchronization.


Asynchronization is easy to understand. When the user program needs to perform Io, it sends an IO request and then immediately returns it. You can continue to do other things.

For example, collect packets from the network. After the packets arrive, they are placed in a cache area of the kernel and placed in the user space required by the Program (one is to directly copy and compare the charged resources; one is ing MMAP), the notification program, the program can then process the data.

This is the most ideal mode, with the highest CPU efficiency.


When the user program needs to perform Io, it sends an IO request and then processes the data after it arrives (first, it copies the data from the kernel space to the user space, ).

How can this problem be solved? One is to block it, And the CPU processes other programs; the other is to return an error if no data is found, and the program can do something else (usually round-robin ), you have to take the initiative to come back and check whether the data is OK.


Synchronization is obviously less efficient, so there are various technologies to improve it. One is Io multiplexing (using a dedicated thread for Io ), including select, poll, and epoll on Linux.

Similar to poll, select uses a kernel-optimized thread to continuously poll Io. Once data is available, user programs can use system calls to copy data from the kernel space to the user space for processing. Although this improves the efficiency, it is still a synchronization mode.

Epoll goes further by adopting the underlying notify mechanism and MMAP. When the underlying data is available, it notifies the IO thread and uses MMAP to directly map the data to the user space. In this case, the user program can directly operate on the data.

Io mode-synchronous (blocking, non-blocking), asynchronous

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.