加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

多核处理器中的线程

发布时间:2020-12-16 09:29:18 所属栏目:百科 来源:网络整理
导读:我用C编写了一个程序,我只想在另一个处理器核心中运行一个函数. 有谁知道如何在不同的核心上分配线程?在一个核心上运行的单个运行线程是否有时可以使用另一个核心,具体取决于核心的繁忙程度? 解决方法 我相信您正在寻找set affinity功能. Processor affini
我用C编写了一个程序,我只想在另一个处理器核心中运行一个函数.

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

解决方法

我相信您正在寻找set affinity功能.

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读