20

Say if I have a processor like this which says # cores = 4, # threads = 4 and without Hyper-threading support.

Does that mean I can run 4 simultaneous program/process (since a core is capable of running only one thread)? Or does that mean I can run 4 x 4 = 16 program/process simultaneously?

From my digging, if no Hyper-threading, there will be only 1 thread (process) per core. Correct me if I am wrong.

4

4 回答 4

23

A thread differs from a process. A process can have many threads. A thread is a sequence of commands that have a certain order. A logical core can execute on sequence of commands. The operating system distributes all the threads to all the logical cores available, and if there are more threads than cores, threads are processed in a fast cue, and the core switches from one to another very fast.

It will look like all the threads run simultaneously, when actually the OS distributes CPU time among them.

Having multiple cores gives the advantage that less concurrent threads will be placed on one single core, less switching between threads = greater speed.

Hyper-threading creates 2 logical cores on 1 physical core, and makes switching between threads much faster.

于 2010-07-09T11:05:20.790 回答
15

这基本上是正确的,显然大多数操作系统允许您同时执行的任务远远多于内核或线程,它们通过交错执行指令来完成。

具有超线程的系统通常具有两倍于物理内核的硬件线程。

于 2010-07-09T11:00:30.130 回答
8

线程一词通常用于描述具有独立于其他线程执行的潜力的操作系统概念。是否这样做取决于它是否卡在等待某个事件(磁盘或屏幕 I/O、消息队列),或者是否有足够的物理 CPU(超线程或非超线程)允许它在面对其他非等待时运行线程。

超线程是 CPU 供应商的术语,意思是单核,可以在两个计算之间多路复用它的注意力。考虑超线程内核的简单方法就像你有两个真正的 CPU,两者都比制造商所说的内核实际可以做的要慢一些。

于 2010-07-09T11:03:12.223 回答
3

基本上这取决于操作系统。线程是持有指令指针的高级构造,并且操作系统将线程执行放置在合适的逻辑处理器上。因此,使用 4 个内核,您基本上可以并行执行 4 条指令。线程仅包含有关要执行的指令以及指令在内存中的位置的信息。

应用程序通常在执行期间使用单个进程,并且操作系统在进程之间切换以给予所有进程“相等”的进程时间。当应用程序部署多个线程时,进程会分配多个执行槽,但在线程之间共享内存。

通常,您会在并发执行和并行执行之间有所不同。并行执行是当您实际物理执行多个逻辑处理器的指令时,并发执行是单个逻辑处理器的频繁切换,从而产生并行执行的外观。

于 2010-07-09T11:16:47.540 回答