开发者

Thread.Sleep(0) will give up acquired CPU resource?

When i specifiy the time interval zero

static void Main()
{
   Thea开发者_如何转开发d.Sleep(0);
}

would the Main() thread give up the CPU resource it acquired or without waiting will it continue?


Yes. The thread shall be suspended for that cycle allowing other threads access to the CPU. The code will be immediately scheduled for the next cycle.

The thread will continue being processed on it's next scheduled CPU slot in a multithreaded environment.

Thread.Sleep(-1) will suspend the thread indefinitely.


Thread.Sleep(0) gives up CPU resources only to the threads with equal or higher priority. If there is thread awaiting with lower priority, it will be ignored.

This is why it is recommended to use Thread.Sleep(1).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜