clr threading model information?
I would like to know how System.Threading.Thread
works in the CLR. I guess threads in the CLR are "lightweight", meaning they are mapped many-to-one to kernel threads... but who schedu开发者_如何学JAVAles these threads? When I create a thread, does it always create a corresponding "kernel" thread unless number of threads is larger than the number of physical cores? Does it try to schedule these threads on the available cores? Any info/sources are greatly appreciated.
You could check SSCLI. It is CLR 2.0 publicly available sources in C++ aka ROTOR project. It is the only place that will reveal the truth :)
UPD: in comments there're clues where to find actual thing in the ROTOR if someone is interested ;)
MSDN:
An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the Fiber API to schedule many managed threads against the same operating system thread, or to move a managed thread among different operating system threads.
there is no "ultimate answer/documentation" to that...
in such cases you usually need to resort to checking the source if available - alternatively use something like Reflector to get to the source... this can be overwhelming quantity-wise but will give you certainly the answers you seek...
精彩评论