When you call the function, what are you doing, the called function doing? - synchronous and asynchronous, blocking and non-blocking

Here I attempt to distinguish and understand a few concepts:

Synchronous, asynchronous, blocking, non-blocking

Basic

When we call a system function in the application process, we want the system to function returns

However, it takes time to generate a result, any function of time required to produce a result, the length of nothing

Thus, two problems derived from

1. How those surveyed know the function has produced results?

2. During this time the called function to produce results, the caller needs to do?

For the first question, we have two ways

Initiative to ask the caller - Synchronization

Inform the caller who is calling - asynchronous

So, we know

It is a description of synchronous and asynchronous invocation result notification

For the second question, we have two ways

The caller has been waiting for, else what is not dry - blocking

The caller doing something else - a non-blocking

So, we know, blocking and non-blocking is a description of the results returned by this time the caller, the caller would you not something else

combination

We already know, synchronous asynchronous, non-blocking is blocking the process of handling calls on two issues

So, we will naturally get their combinations of two, we look one by one

Synchronous blocking: the caller initiative inquiry results, during which time the results generated caller, the caller has been waiting for the results, what else do not

Synchronous non-blocking: the caller initiative inquiry results, during which time the results generated caller, the caller regular query results generated situation, other times to do other things

Asynchronous blocking: the caller is notified of the caller, this time to generate results in the caller, the caller what is not dry

Asynchronous non-blocking: the caller's caller is informed, during which time the results generated caller, the caller do other

Among them, in this way blocking asynchronous

As a result of asynchronous notification, and therefore within the waiting time, the caller can do other things, but he did not do it

This is in actual use uneconomical, so this way does not occur in actual use, it is listed here for completeness discussion

further

We have seen, under the premise of asynchronous notification messages, in most cases we will choose instead of blocking, non-blocking

Because blocking means that the process hangs, can not respond to subsequent requests

In synchronous notice premise, in order to achieve non-blocking, caller process had to polling, which requires a certain amount of cpu time consuming

There is no better way to achieve non-blocking?

Asynchronous notification occurs, so as to achieve non-blocking is more convenient and economical

The caller need not polling, you can throw off arm doing their own thing, until the results go back for processing results

We can say that the achievements of non-blocking asynchronous, or that in order to achieve non-blocking, people invented asynchronous

(The last sentence is purely brain-dong)

Guess you like

Origin www.cnblogs.com/jiage666/p/11626710.html