当前位置:网站首页>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
边栏推荐
- xargs 的作用详解
- 字节序问题
- Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model
- How to add a "security lock" to the mobile office of government and enterprises?
- 缓冲
- Mot - clé C facile à comprendre statique
- shell curl 执行脚本,带传参数,自定义参数
- Cs144 environment configuration
- recv & send
- Finding the sum of N multiplications
猜你喜欢

biggan:large scale gan training for high fidelity natural image synthesis

recv & send

Interpretation of script corresponding to postman assertion

阳光男孩陈颢天 受邀担任第六季完美童模全球总决赛代言人

Dataframe extracts data from a column and converts it into a list

Sunshine boy chenhaotian was invited to be the spokesperson for the global finals of the sixth season perfect children's model

Abnova CSV monoclonal antibody solution

Exploring temporary information for dynamic network embedding

安装了Visual Studio 2013 Redistributable,mysql还是安装失败

recvmsg & sendmsg
随机推荐
如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中
shell学习记录(一)
Pixel6 unlock bootloader
shell学习记录(二)
jenkins汉化及汉化无效解决方案
shell学习记录(三)
接口测试用例设计
Introduction to gun make (1)
PTA class a simulated 8th bomb: 1164-1167
Several methods of JQ obtaining objects
Reverse output an integer
Eight principles of element positioning
Redis-SDS
图形渲染管线
One stop solution EMQ for hundreds of millions of communication of Internet of things
Byte order problem
Abnova CMV CISH probe solution
The answer skills and examples of practical cases of the second construction company are full of essence
俏皮少女王艺璇 受邀担任第六季完美童模全球总决赛推广大使
On the difference between strlen and sizeof