How often does Windows (usually) do a thread switch per second? Is this different from .NET threads? Or asked the other way around: How long is a thread (of, say, normal thread priority) allowed to run?
How often Windows context switches depends on the system "quantum". This quantum ranges from 10-15 milliseconds (66-100 times per second) depending on whether the OS is client or server. For more detail I recommend reading Joe Duffy's book Concurrent Programming on Windows; it goes into great detail about things like this--e.g. details that "client OSes ... is 2 clock intervals. ...on server OSes... is 12 clock intervals". Also, his article [CLR Inside Out: Using concurrency for scalability][1] is a must read.
You can sort of "edit" the quantum length. If you set the "Adjust for best performance of:" in Performance Options/Advanced in System Properties to "Programs", you'll get a shorter quantum. If you set it to "Background services" you'll get a longer quantum.
If there's no reason to context switch, a thread will get as much time as it needs.
[1] http://www.360doc.cn/article/28217_2474333.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With