linux - 2个线程可以并发运行吗?或者只有 1 个? (考虑到超线程的可能性)

标签 linux multithreading cpu multicore

以下是 cat/etc/cpuinfo 的输出,并没有说明内核是否是超线程的。如何确定两个线程是否可能同时运行?

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 26
model name  : Intel(R) Xeon(R) CPU           E5507  @ 2.27GHz
stepping    : 5
microcode   : 0x11
cpu MHz     : 2266.750
cache size  : 4096 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 6
fpu     : yes
fpu_exception   : yes
cpuid level : 11
wp      : yes
flags       : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc up rep_good nopl nonstop_tsc pni ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm
bogomips    : 4533.50
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

最佳答案

How do I find out whether or not two threads can potentially run concurrently?

如果只有 processor: 0 那么你有一个物理 CPU。这意味着一次只能有一个线程真正运行。引用自 wikipedia page on Hyperthreading :

They appear to the OS as two processors, thus the OS can schedule two processes at once. In addition two or more processes can use the same resources. If one process fails then the resources can be readily re-allocated.

所以我很确定即使使用超线程,它们也会在您的 EC2 虚拟机中显示为多个 CPU 条目:处理器:1,处理器:2,...如果它们存在的话。

关于linux - 2个线程可以并发运行吗?或者只有 1 个? (考虑到超线程的可能性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10183675/

相关文章:

linux - 使用 Native Library 在 Linux 系统上安装 Tomcat 7

c# - 将秒表与异步方法一起使用

c++ - Win32 C++ : Get process CPU affinity?

linux - 如果 CPU 平均负载很高会发生什么

linux - shell 获取解析参数

linux - Bash shell 脚本来获取子字符串?

python - 使用Python并行处理图像的分割和连接

c++ - 在函数方法中使用 std::thread

arm - ARM 中 TPIDR_EL0/TPIDR_EL1 等线程 ID 寄存器的用途是什么?

linux - 将DICOM图像转换为PNG的最简单方法是什么?