当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
Fiddler tool explanation
二叉树进阶复习1
版本号命名规则
支持触屏slider轮播插件
C语言制作-QQ聊天室
v-if/v-else根据计算判断是否显示
数据库——概述
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)
Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
MongoDB 语法大全
Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation
达梦数据库大表添加字段
Antdesign a-select 下拉框超出长度换行显示
MM上街前的折腾(有趣)
Chapter 12 贝叶斯网络
Use of thread pool (combined with Future/Callable)
P1160 队列安排
pnpm 是凭什么对 npm 和 yarn 降维打击的
漂亮MM和普通MM的区别
强网杯2022 pwn 赛题解析——house_of_cat









