(在Java或C ++程序中)线程与CPU中的内核数之间是什么关系? [英] What is the relationship between threads (in a Java or a C++ program) and number of cores in the CPU?

查看:70
本文介绍了(在Java或C ++程序中)线程与CPU中的内核数之间是什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给它一些启发吗?

Can someone shed some light on it?

一个i7处理器可以运行8个线程,但是我很确定我们可以在JAVA或C ++程序中创建8个以上的线程(虽然不确定).我有一个i5处理器,在研究并发性时,我创建了10个用于分配的线程.我只是想了解CPU的核心等级与线程之间的关系.

An i7 processor can run 8 threads but I am pretty sure we can create more than 8 threads in a JAVA or C++ program(not sure though). I have an i5 processor and while studying concurrency I have created 10 threads for assignments. I am just trying to understand how Core rating of CPU is related to threads.

推荐答案

您所引用的线程称为软件线程;只要您的操作系统允许,您就可以根据需要创建任意数量的软件线程.每个软件线程或代码片段都可以从其他线程同时 运行.

The thread you are refering to is called a software thread; and you can create as many software threads as you need, as long as your operating system allows it. Each software thread, or code snippet, can run concurrently from the others.

对于每个内核,至少有一个 硬件线程,操作系统可以向其分配软件线程.例如,如果您有8个核心,则您有一个容量为8的硬件线程池.您可以将数十或数百个软件线程映射到该8插槽池,在该池中,实际上只有8个线程同时在硬件上运行,即 并行 .

For each core, there is at least one hardware thread to which the operating system can assign a software thread. If you have 8 cores, for example, then you have a hardware thread pool of capacity 8. You can map tens or hundreds of software threads to this 8-slot pool, where only 8 threads are actually running on hardware at the same time, i.e. in parallel.

软件线程就像共享同一台计算机的人一样.每个人最多可以使用这台计算机一段时间,不必一定要完成任务,然后再交给另一台计算机.

Software threads are like people sharing the same computer. Each one can use this computer up to some time, not necessarily have his task completed, then give it up to another.

硬件线程就像每个人都有一台计算机的人.他们所有人都可以同时执行任务.

Hardware threads are like people having a computer for each of them. All of them can proceed with their tasks at the same time.

注意:对于i7,有

Note: For i7, there are two hardware threads (so called hyper-threading) in each core. So you can have up to 16 threads running in parallel.

这篇关于(在Java或C ++程序中)线程与CPU中的内核数之间是什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆