Linux:多核CPU中的进程和线程 [英] Linux: Processes and Threads in a Multi-core CPU

查看:54
本文介绍了Linux:多核CPU中的进程和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与进程相比,线程是否更不可能从多核处理器中受益?换句话说,内核会决定在单个内核上而不是在多个内核上执行线程吗?

Is it true that threads, compared to processes, are less likely to benefit from a multi-core processor? In other words, would the kernel make the decision of executing threads on a single core rather than on multiple cores?

我说的是属于同一进程的线程.

I'm talking about threads belonging to the same process.

推荐答案

我不知道(各种)Linux调度程序如何处理此问题,但是当线程在不同的Core上运行时,线程间通信的成本会更高.

I don't know how the (various) Linux scheduler handle this, but inter-thread communication gets more expensive when threads are running on different Cores.

因此,如果还有其他需要CPU时间的进程,则调度程序可以决定在同一CPU上运行进程的线程.

So the scheduler may decide to run threads of a process on the same CPU if there are other processes needing CPU time.

例如,使用双核CPU,如果有两个具有两个线程的进程,并且所有进程都使用了它们获得的所有CPU时间,则最好在第一个Core上运行第一个进程的两个线程,而在第一个Core上运行两个线程.第二个核心上的其他过程.

Eg with a Dual-Core CPU, if there are two processes with two threads and all are using all CPU time they get, it is better to run the two threads of the first process on the first Core and the two threads of the other process on the second core.

这篇关于Linux:多核CPU中的进程和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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