Synchronous and asynchronous (comparison of blocking and non-blocking in two ways)

Synchronized

Synchronization is sharing, if it is not shared resources, there is no need to synchronize

Asynchronous

Asynchrony means independence, and there is no restriction on each other, just like the ajax when we learned http. We can continue to browse or manipulate the content of the page after sending an ajax request, there is no relationship between the two.

Concept summary

From the above example, we can understand one thing, synchronous and asynchronous, blocking and non-blocking, they target different objects. It is blocking and non-blocking for the caller, and the callee is synchronous and asynchronous.

Synchronization: A calls B, and only returns when B has a result.
Asynchronous: A calls B and B returns immediately without waiting. When B finishes processing, it will tell A the result through notification or callback function.
Blocking: A calls B, A will be suspended, waiting for the result of B, nothing can be done.
Non-blocking: A calls B, and is suspended and waits for the result of B, and can do other things.

Synchronous blocking

It was a holiday, and Lao Wang returned to the countryside. Due to the poor infrastructure in the countryside, when he was waiting at the station, he could only wait until the bus arrived.
At this time, for the bus (the callee), it is "synchronized". Lao Wang (caller) was "blocked" on the platform by the bus (callee).

Asynchronous blocking

After the holiday, Pharaoh returned to the big city and started to work. He also waited at the station and waited at the station. However, the infrastructure of the big city is well constructed. When the bus arrives, there will be broadcast reminders. passenger.

At this time, for the bus (the callee), it is "asynchronous", and the caller will be notified when it arrives. But at this time, Lao Wang (caller) was still "blocked" on the platform by the bus (callee).

Synchronous non-blocking

After the New Year, Lao Wang came back to the countryside during his holiday and was about to wait for the bus again. At this time, he became smarter. Instead of waiting at the station all the time, he went to find the little flower next door to reminisce about the past. But I was afraid that I would miss the car when it arrived, so I had to come over to see if the car arrived.

At this time, for the bus (the callee), it is "synchronized". But at this time, Lao Wang (caller) can do other things while waiting for the bus, so he is "non-blocking".

Asynchronous non-blocking

The spring breeze of reform is blowing all over the ground, and the construction of a new rural area is in full swing. At this time, in the countryside, the bus has also installed a reminder of the arrival of vehicles. Now when Pharaoh is waiting for the bus, he can feel at ease with Xiaohua. When he hears the announcement of the vehicle he needs to take, he will go to the station and get on the train.

At this time, for the bus (the caller), it is "asynchronous". It will broadcast a reminder when it arrives. At this time, Lao Wang (caller) can do other things while waiting for the bus, so he Is "non-blocking"

Guess you like

Origin blog.csdn.net/qq_41489540/article/details/109109519