超线程 CPU 上的硬件线程(逻辑核心)调度程序
我知道软件线程需要一定的时间来执行,每个软件线程轮流执行该时间块,但它们不会同时执行(在单个硬件线程上)。
我的问题是,当每个核心有 2 个或更多硬件线程时,每个硬件线程是否在该核心上同时运行,或者硬件线程是否像软件线程一样获得时间块来执行,玩循环游戏?
硬件线程=逻辑核心
I know that software threads get a certain bit of time to execute and each software thread takes turns executing for that block of time but they are not executing at the same time (on a single hardware thread).
My question is, when you have 2 or more hardware threads per core, does each hardware thread run concurrently on that core or do hardware threads get blocks of time to execure like software threads, playing the round robin game?
Hardware thread = logical core
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个(逻辑)核心只有 1 个(硬件)线程。
英特尔通过在 1 个物理核心上运行两个逻辑线程来混淆视听,因此仅对于某些处理器您的问题适用。超线程很复杂,但大多是并发的。
对于我们程序员而言,只存在一次运行 1 个线程的逻辑核心。
You only have 1 (hardware) Thread per (logical) Core.
Intel muddies the water by running two logical Threads on 1 Physical core, so only for some processors your question is applicable. And Hyper-threading is complicated but mostly concurrent.
For as far we as programmers are concerned, there exist only logical cores running 1 thread at a time.
如果您谈论的是具有超线程的处理器,那么该处理器在执行周期的大部分时间里都有额外的执行管道。就 .net 应用程序而言,是的,您将不会像软件线程那样进行时间切片和锁定。您仍然需要确保您的操作是线程安全的,否则您将需要自己进行锁定,以确保您不会通过同时从多个线程调用对象来损坏对象。验证这一点的快速测试是使用具有超线程的计算机,生成一些执行处理器繁重操作的线程并查看 CPU 使用情况。如果您看到所有虚拟核心都处于 100%,那么您就很成功了。
If you are talking about a processor with hyper threading, then that processor has extra execution pipelines for most parts of the execution cycle. As far as a .net app cares, then yes you will not have the time slicing and locking that a software thread has. You still need to ensure that your operations are thread safe, otherwise you will need to do your own locking to ensure that you don't corrupt your objects by calling them from multiple threads at the same time. A quick test to validate this is to use a computer with hyper threading, spawn off some threads that do processor heavy operations and look at the cpu usage. If you see all of the virtual cores at 100% then you are golden.