2010-08-16 140 views
3

我已经用C编写了一个程序,而我只希望只有一个函数在另一个处理器核心中运行。多核心处理器中的线程

有谁知道如何在不同的内核上分配线程?一个内核上运行的单个运行线程有时可以使用另一个内核,具体取决于内核的繁忙程度。

+6

这是否通过某种机器翻译? – Hasturkun 2010-08-16 12:06:28

回答

5

我相信你正在寻找设置亲和力功能。

Processor affinity is a modification of the native central queue scheduling 
algorithm in a symmetric multiprocessing operating system. Each task 
(be it process or thread) in the queue has a tag indicating its 
preferred/kin processor. At allocation time, each task is allocated to 
its kin processor in preference to others. 

退房this thread其中讨论设置亲和力特定线程的使用。从这个线程 摘录:

int sched_setaffinity(pid_t pid,size_t cpusetsize,cpu_set_t *mask); 

Passing 0 as the pid, and it'll apply to the current thread only, or have other 
thread report their kernel pid with the linux specific call pid_t gettid(void); 
and pass that in as the pid. 
2

,我认为你是问你怎么线程都分配到一个多处理器的CPU在不同的处理器上运行?如果是这样,我的理解是这是由操作系统控制的东西。看看这个SO question

+0

首先想你。但是,我不希望parallet与.NET,但与C unter Linux,没有api或c Libary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! – farka 2010-08-16 13:02:09