当前位置:网站首页>One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
2022-06-26 02:01:00 【Murong Tianyu】
I talked with brother Xu about the concurrency mechanism today , We have learned the difference between synchronous and asynchronous blocking and non blocking , Sum it up , Strengthen understanding , I don't say much nonsense , Just do it .
Raise questions
What's the difference between synchronous and asynchronous ?
What is the difference between blocking and non blocking ?
You can try to think about it in your mind , Have your own answer first , Then look down
.
.
.
.
.
.
Take a look at the answer
Synchronous and asynchronous are concerned with the way values are returned ,
Synchronization means that the service provider responds to the user after processing .
Asynchrony means that the service provider returns a value that has received the request first , Then the result will be returned after the actual processing , Or the caller requests to pull the result .
The focus of blocking and non blocking is the state of the caller
Blocking occurs when the server is processing , The state of the caller is doing nothing .
Instead of blocking, it is when the server handles , The caller does his own thing , Don't wait here , The caller queries the results by himself , Or the service provider notifies the caller when there is a result .
Advantages and disadvantages
Blocking
advantage : It can return data in time , There is no delay .
shortcoming , It takes time to wait .
Non blocking
advantage : Compare with blocking , Non blocking does not require waiting for task results , You can do other tasks , So it is better to support concurrency .
shortcoming : Unable to obtain the returned results in time . Because I only go back to ask at regular intervals , But the task may be completed within the time interval between the two asking actions , This leads to a reduction in the overall data throughput .
The combined scene
Let's take a look at the combined scenario through examples 
Synchronous blocking
Xiaoming goes to mingmingyuan to eat rice noodles , I ordered a rice noodle with minced meat , The waiter said it would take about half an hour , You have to wait . Then Xiao Ming did nothing and waited here , Wait until you're ready to go and find a seat .
BIO Is the synchronous blocking mode , Most of the methods we write are synchronous blocking .
Synchronous nonblocking
Or this one ,
When the master is sitting on rice noodles , Xiao Ming is not idle , He went to a seat , He brushed his cell phone for a while , But every time 10 minute , He went to see if the meal was ready .
NIO Synchronous non blocking mode ,
Asynchronous non-blocking
continue
Xiao Ming finished the rice noodles , The waiter gave Xiao Ming a number , Say rice noodles. I'll call you , Then Xiao Ming went to his seat to remember the words .
AIO Is asynchronous non blocking mode ,Callable And some with callback methods are in asynchronous non blocking mode .
Asynchronous blocking
This is a stupid way , Generally, no one will use it
边栏推荐
猜你喜欢
随机推荐
Code coverage test (I)
一分钟了解同步、异步、阻塞和非阻塞的区别
PTA class a simulated first bomb: 1132-1135
readv & writev
shell curl 执行脚本,带传参数,自定义参数
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Redis-SDS
About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi
Make a row of the dataframe a column name
xargs 的作用详解
Abnova actn4 DNA probe solution
PTA class a simulated fifth bomb: 1148-1151
Abnova CMV CISH probe solution
tos cos dscp 区别和作用
Talking about interface test (2)
Pre ++, post ++ and pre -- and post -- (+a, a++ and --a, a--)
Eight principles of element positioning
Dazhou suggested that we media bloggers do these four things in the early stage
LeetCode 31 ~ 40
PTA class a simulated second bullet: 1136-1139








