Thread.Sleep(0) : What is the normal behavior?

后端 未结 5 1388
渐次进展
渐次进展 2020-12-05 10:13

To my understanding a Thread.Sleep(0) force a context switch on the OS.

I wanted to check what was the maximum amount of time that could pass in an application befor

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 10:37

    Most likely cause is that you aren't allowing the program to read instructions in an efficient manner.

    When you invoke Sleep(0) your code is suspended for a single cycle and then scheduled for the next available slot. However, this context switching isn't free - there are plenty of registers to save/load, and when you have a different sequence of instructions to read from disk you probably end up with quite a few cache misses. I can't imagine this having a significant impact on your application in most cases, but if you are working with a real-time system or something similarly intensive then it might be a possibility.

提交回复
热议问题