当前位置:网站首页>Why should the coroutine be set to non blocking IO
Why should the coroutine be set to non blocking IO
2022-06-25 14:53:00 【Mr . Solitary patient】
Preface
It used to be thought that the coordination process was in read 、 write before yield Give up the process , Wait for the data to arrive resume Come back , Carry out subsequent processing , Suppose you use blocking io, I just need to be in eventloop Medium epoll_wait Set up timeout Still able to achieve asynchrony , therefore io Whether it is blocked or not has nothing to do with the whole process ( Anyway, you have to let it out before you get stuck ), But when I was writing code these two days, I thought it over carefully and found that this idea was wrong , The coroutine must use non blocking io.
reason
The reason for the above idea is that the multithreading of the program is not considered , When blocked io perform epoll_wait When , The current thread will switch from user mode to kernel mode , And suspend within the operating system , So the operating system goes back to executing other threads , Then the suspended thread will not be able to continue execution once there is a process timeout or the data processing is completed , Wait until epoll_wait Timeout and return to user status , And the operating system puts cpu Switch back to this thread to execute .
边栏推荐
- How to crop GIF dynamic graph? Take this picture online clipping tool
- High precision addition
- Add the resources directory under test in idea
- One question per day, a classic simulation question
- Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
- Installing QT plug-in in Visual Studio
- JGG | overview of duhuilong group of Hebei University Research on plant pan genomics
- Output 0 ~ n digits and output multiple times
- Judging the number of leap years from 1 to N years
- Does stream even have application advanced learning? As a programmer, you know what
猜你喜欢
[untitled] the CMD command window displays' NPM 'which is not an internal or external command
[try to hack] vulhub shooting range construction
【Try to Hack】vulnhub DC1
Does stream even have application advanced learning? As a programmer, you know what
15 -- 最接近原点的 K 个点
JGG | 河北大学杜会龙组综述植物泛基因组学研究
如何裁剪动图大小?试试这个在线照片裁剪工具
Gif动画怎么在线制作?快试试这款gif在线制作工具
15 -- k points closest to the origin
QT loading third-party library basic operation
随机推荐
dmsetup命令
If multiple signals point to the same slot function, you want to know which signal is triggered.
【HBZ分享】LockSupport的使用
Async await to achieve sleep waiting effect
Is it safe to open an online stock account? Who knows
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
Remove interval (greedy)
One question per day, a classic simulation question
Uniapp cloud packaging app
Qlogsystem log system configuration use
【中国海洋大学】考研初试复试资料分享
QT inline dialog
Where is it safe to open an account for buying funds? Ask for guidance
JGG | overview of duhuilong group of Hebei University Research on plant pan genomics
Native JS obtains form data and highlights and beautifies JSON output display
Yolov3 spp Darknet version to caffemodel and then to OM model
Arithmetic operations and expressions
[try to hack] vulhub shooting range construction
【深度学习】多任务学习 多个数据集 数据集漏标
One question per day,