当前位置:网站首页>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
边栏推荐
- recvmsg & sendmsg
- Easyexcel read file
- Pointnet/Pointnet++学习
- PTA class a simulated fifth bomb: 1148-1151
- PTA class a simulated sixth bomb: 1156-1159
- General introduction to gun make (2)
- Dataframe extracts data from a column and converts it into a list
- Talking about interface test (2)
- App test (I)
- Differences and functions of export set env in makefile
猜你喜欢

Xiaomi tablet 5 Pro unlock bootloader

The 19th - 22nd week of scientific research training - about tnet and memnet

recv & send

Easy to understand C language keyword static

readv & writev

甜酷少女金书伊 受邀担任第六季完美童模全球总决赛代言人

Assertion of postman interface test

tos cos dscp 区别和作用

二造实务案例答题技巧和举例汇总,满满都是精髓

CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
随机推荐
Dataframe extracts data from a column and converts it into a list
Talking about interface test (I)
Easy to understand C language keyword static
Make a row of the dataframe a column name
LeetCode 41 ~ 50
easyexcel读取文件
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
UN make (6) makefile的条件执行
The 19th - 22nd week of scientific research training - about tnet and memnet
一分钟了解同步、异步、阻塞和非阻塞的区别
jenkins汉化及汉化无效解决方案
wifi 相关知识详解
Gun make (7) execute make
regular expression
PTA class a simulated fifth bomb: 1148-1151
Sweet cool girl jinshuyi was invited to be the spokesperson for the global finals of the sixth season perfect children's model
Byte order problem
输入3个整数,从大到小输出出来
Web Testing
PTA class a simulated 11th bomb: 1124-1131