CPU friendly infinite loop

前端 未结 11 1921
心在旅途
心在旅途 2020-12-04 09:15

Writing an infinite loop is simple:

while(true){
    //add whatever break condition here
}

But this will trash the CPU performance. This ex

11条回答
  •  爱一瞬间的悲伤
    2020-12-04 09:43

    To expound on a comment CodeInChaos made:

    You can set a given thread's priority. Threads are scheduled for execution based on their priority. The scheduling algorithm used to determine the order of thread execution varies with each operating system. All threads default to "normal" priority, but if you set your loop to low; it shouldn't steal time from threads set to normal.

提交回复
热议问题