Significance of Sleep(0)

前端 未结 8 2096
醉酒成梦
醉酒成梦 2020-12-03 02:19

I used to see Sleep(0) in some part of my code where some infinite/long while loops are available. I was informed that it would make the time-slice

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 02:48

    Sleep(0) is a powerful tool and it can improve the performance in certain cases. Using it in a fast loop might be considered in special cases. When a set of threads shall be utmost responsive, they shall all use Sleep(0) frequently. But it is crutial to find a ruler for what responsive means in the context of the code.

    I've given some details in https://stackoverflow.com/a/11456112/1504523

提交回复
热议问题