clr 线程模型信息?

发布于 2024-11-28 08:13:14 字数 187 浏览 0 评论 0原文

我想知道 System.Threading.Thread 在 CLR 中是如何工作的。我猜想 CLR 中的线程是“轻量级”的,这意味着它们被多对一地映射到内核线程……但是谁来调度这些线程呢?当我创建一个线程时,它是否总是创建一个相应的“内核”线程,除非线程数大于物理核心数?它是否尝试在可用内核上调度这些线程?非常感谢任何信息/来源。

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 schedules 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独夜无伴 2024-12-05 08:13:14

你可以检查 SSCLI。它是 C++ 又名 ROTOR 项目中的 CLR 2.0 公开可用源。这是唯一能揭示真相的地方:)

UPD:如果有人感兴趣,在评论中可以找到在 ROTOR 中找到实际东西的线索;)

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 ;)

2024-12-05 08:13:14

MSDN

操作系统 ThreadId 与托管线程没有固定关系,因为非托管主机可以控制托管线程和非托管线程之间的关系。具体来说,复杂的主机可以使用 Fiber API 针对同一操作系统线程调度许多托管线程,或者在不同操作系统线程之间移动托管线程。

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.

扬花落满肩 2024-12-05 08:13:14

对此没有“最终答案/文档”...

在这种情况下,您通常需要检查源(如果有) - 或者使用诸如 Reflector 之类的东西来获取源...这可能是压倒性的数量-明智的,但肯定会给你你寻求的答案......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文