Linux synchronous asynchronous, blocking some ideas of non-blocking

Source: Internet
Author: User
Tags epoll

synchronous asynchronous blocking non-blocking

Today and the small partners to discuss this issue, the online statement there are many kinds of, I follow my own ideas to summarize one side.
A sentence summarizes the difference:
Synchronous Async is concerned with your behavior when an event occurs.
The state of the wait event that is blocking the non-blocking concern.
Here's a look at the specific analysis

Synchronous Asynchronous

Synchronous:
Before the event occurs, your status is to keep an eye on this event, waiting for this event to return the result to you.
Example:
Water heating, synchronization is that you always pay attention to it, a period of time, the kettle smoke, you see, you know the waters have been burnt well.
So during this time you need to keep watching it smoke.

Asynchronous:
Before the event, you do not care about this event, but you go to your own, the event will notify you when the completion.
Example:
When the water is burning, the kettle will beep, you hear it, it means the water is burning.
So during this time you don't have to keep looking at it and hear the sound indicating that the water has been burnt well. Sound is the notification mechanism.

blocking non-blocking

Blocking:
Blocking is when you wait for an event to hang, and you can't do anything at this time, only waiting for the event.
Example:
When you boil water, you just wait for it to open beside the kettle, and you know it immediately.

Non-blocking:
Non-blocking is waiting for an event if the event does not occur and does not suspend itself
Example:
When you boil water, you come over and look at it, it's not open, it's gone, after a while, it's not good, so keep repeating until the water is open.

synchronous asynchronous blocking non-blocking combinations

The network IO is basically divided into the following steps:
Waiting for data –> from the kernel state to the user state (copy data) on the NIC

5 Types of IO models

Synchronous Blocking:

At the beginning of our learning Network programming must write the synchronous blocking IO model, always focus on the other side of the event, if the other side no message is blocked on the read system call.
such as 1 parts, network IO Two steps have been blocking.

synchronous non-blocking:

We can set the socket socket to non-blocking, then it will appear in the second case, the constant check until the event occurs, it is still blocked in the copy data phase. There is no data to block there.
In the third case, the I/O multiplexing,select blocks in the Select function, poll blocks in the poll function, Epoll blocks in the Epoll_wait function, and their second phase is blocked.

separate I/O multiplexing
Many people on the internet will epoll into asynchronous non-blocking, I think it is wrong, conceptually, asynchronous, from the beginning of the event I am not concerned about this event, you finished telling me, and Epoll is not, if there is no data it will block in Epoll_wait, I think maybe some people from the advantages of Epoll feel that Epoll is really asynchronous, because epoll_wait each return is a ready event, let people think "I do not care, it returned to me is the ready event!" ", in fact, is not right, the network IO is said to be divided into two steps, Epoll_wait will block the second step to copy the data, then it is blocked, any one of the steps blocking will block.

asynchronous non-blocking:

Linux should be aio_* a set of APIs, but the Linux asynchronous IO support is not good, online criticism of the article a lot.
You can refer to this article
Linux Kernel Aio this wonderful
Asynchronous non-blocking instructions we do not have to care about the event execution process, the event after the completion of the message to us, we accept it, will not block on the network card, will not block on the copy data. (Note: Blocking is also blocking on copy data).

Asynchronous blocking

Haven't heard of, personally think there is no asynchronous blocking this said, async can not block, checked the data is objected to the IBM article posted
Use asynchronous I/O to greatly improve application performance
See a little think there is a problem.
He's asynchronous blocking I/O refers to Epoll.

Finally, the above is only a number of personal views and views, we learn or to take a look at the vision, need to have their own ability to judge knowledge.

If the content of the article is problematic, please also indicate ^_^

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux synchronous asynchronous, blocking some ideas of non-blocking

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.