Significance of Sleep(0)

前端 未结 8 2144
醉酒成梦
醉酒成梦 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

    I'm afraid I can't improve on the MSDN docs here

    A value of zero causes the thread to relinquish the remainder of its time slice to any other thread that is ready to run. If there are no other threads ready to run, the function returns immediately, and the thread continues execution.

    Windows XP/2000: A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. This behavior changed starting with Windows Server 2003.

    Please also note (via upvote) the two useful answers regarding efficiency problems here.

提交回复
热议问题