当前位置:网站首页>Thinking after writing a code with a very high CPU usage
Thinking after writing a code with a very high CPU usage
2022-08-05 08:08:00 【code beans】
1 If you write an infinite loop without any delay, the CPU usage will skyrocket.
2 Task.Delay() is an asynchronous delay, which cannot be delayed when written in synchronous code.
3 Thread.Sleep(0) does not really want the thread to be suspended for 0 milliseconds. The meaning is that the current thread calling Thread.Sleep(0) is indeed frozen this time, giving other threads a chance to execute first.Thread.Sleep(0) means that your thread temporarily gives up the cpu, that is, releases some unused time slices for use by other threads or processes, which is equivalent to an abdication action.
4 Writing a Thread.Sleep(0) in an infinite loop will not cause the CPU usage to soar.
边栏推荐
- 图扑软件与华为云共同构建新型智慧工厂
- Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
- Jmeter永久设置中文界面
- 路由----router
- MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
- 行业应用软件项目经理三步曲
- Access Denied: "microsoft.web.ui.webcontrols" workaround
- window.open 全屏展示
- 执子之手,与子偕老。你同意么?
- Antdesign a-select 下拉框超出长度换行显示
猜你喜欢

利用Jenkins的持续集成

MVCC of Google's Fragmented Notes (Draft)
![[Structure internal power practice] Structure memory alignment (1)](/img/31/4ddc16810da8238ac95a93d007e12e.png)
[Structure internal power practice] Structure memory alignment (1)

微信 小程序 之PC端 不支持 wx.previewMedia 方法 故用自定义轮播图进行 模拟照片视频的播放

busybox 知:构建

EA谈单机游戏:仍是产品组合中极其重要的部分

unity urp 渲染管线顶点偏移的实现

网络安全研究发现,P2E项目遭遇黑客攻击只是时间问题

Data source object management Druid and c3p0

高端无主灯设计灯光设计该如何布置射灯灯具?
随机推荐
Win10 设置锁屏壁纸提示尝试其它图片
Redis缓存以及存在的问题--缓存穿透、缓存雪崩、缓存击穿及解决方法
图片地址转为base64
U++ 创建UI
剑指Offer面试题解总结1-10
C-Eighty seven(背包+bitset)
漂亮MM和普通MM的区别
MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
游戏模拟器成了外挂帮凶,灰产对抗再升级
力扣每日一题
Embedded Systems: Basic Timers
【每日一题】1403. 非递增顺序的最小子序列
青苹果论坛重新开放
php向mysql写入数据失败
MVCC of Google's Fragmented Notes (Draft)
php向mysql写入数据失败
星座理想情人
唤醒手腕 - 微信小程序、QQ小程序、抖音小程序学习笔记(更新中)
openSource 知:社区贡献
D2--FPGA SPI接口通信2022-08-03