Read on to understand what is synchronous/asynchronous, blocking/non-blocking

Source: Internet
Author: User

Believe that the dry it more or less have heard of synchronous, asynchronous, blocking, non-blocking the four words, they can also be divided into two pairs, that is, synchronous, asynchronous pair, blocking, non-blocking a pair, this look at the word meaning is very good understanding. The key problem is the difference between synchronous and blocking, asynchronous and non-blocking, a lot of people are a bit confused about these two sets of concepts, feel the same meaning, in fact, they describe two different problems, we use a specific scenario to describe the four words, with real life scenes to feel their differences.

We should all have past bank counters to handle business experience, when people often have to wait in line, then this time there may be four kinds of situations:

The front line of the counter has been waiting there for business (sync) and not doing anything else until the business is processed (blocked);

In front of the counter has been waiting there for business (sync), wait until the business to do other things, such as playing mobile phones, play mobile phone when you need to see whether the line has been queued (non-blocking);

Go to pick up a number on the machine, when the turn to the business will be a number of times, do not have to wait there (async), in the station-to-person business before doing anything else (blocking);

To pick up a number on the machine, when the turn to handle the business will be called, do not have to wait there (async), in the call-to-station business before doing other things, such as playing mobile phones, play mobile phone without concern whether queuing line, because will be called to notify me (non-blocking);

By going to the bank counter to transact the business scene we can find that synchronous/asynchronous, blocking/non-blocking between the points of interest is different , synchronous/asynchronous concern is how the message notification, in the above scene is two different notification methods: Synchronous notification method is the queue of people have been waiting for the message, The asynchronous notification method is the main difference between synchronous/asynchronous because the message is sent by a station-to-station notification, and the queuing person does not need to pay attention to the message. Blocking/non-blocking attention is waiting for the status of the message notification, blocking when the state of the queue has been waiting, non-blocking time can become other non-waiting status, such as watching mobile phones, go out to smoke and so on. What needs to be explained is that the synchronous non-blocking state, you can find that while doing other things need to constantly check the waiting results, so there is a task switching caused by the resource consumption problem.

Now let's summarize the differences between synchronous/asynchronous, blocking/non-blocking: 同步和异步仅仅是关注的消息如何通知的机制,而阻塞与非阻塞关注的是等待消息通知时的状态 . In other 同步的情况下,是由处理消息者自己去等待消息是否被触发,而异步的情况下是由触发机制来通知处理消息者。 words,

  I believe that after reading you have basically understood the concept of synchronous/asynchronous, blocking/non-blocking, and then we use a life example to strengthen the review to see if they really have mastered.

Usually we will download some things online, here is the assumption that I want to download a video, we use this scene to review the concept of synchronous/asynchronous, blocking/non-blocking:

I wait for the download to finish (sync) by looking at the download precision bar, and do nothing else during the time (blocking)

I look at the download accuracy bar waiting for the results of the download (synchronization), during the chat QQ, chatting QQ constantly to see if the download is complete (non-blocking)

Get the results of download completion (asynchronous) by downloading the completed beep notification, and do nothing else during the period (blocking)

The completion of the download through the sound notification of the completion of the download (asynchronous), during the chat QQ, when chatting QQ do not need to see the download is complete, because the sound will notify me when the download (non-blocking)

  最后,需要注意理解的是“消息通知机制”和“等待消息通知时的状态”这两个概念,这是理解同步/异步、阻塞/非阻塞四个概念的关键所在。还有我们在讨论这四个概念的时候一定要放在同一个层级,比如操作系统级别,框架级别,业务代码级别等,因为一个事件在不同层级所属的性质不一定一样,只有在同一个层级,才能去讨论它的性质是同步/异步还是阻塞/非阻塞。




Read on to understand what is synchronous/asynchronous, blocking/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.