有没有办法到进程锁定到CPU? [英] Is there a way to lock a process to a CPU?

查看:196
本文介绍了有没有办法到进程锁定到CPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个应用程序,将,六芯机上跑了六异步任务,一个在每个核心。

I am thinking about developing an application that will, on a six core machine, run six asynchronous tasks, one on each core.

不过是有可能的任务锁定在自己的核心?

But is it possible to lock the tasks to their own core?

的想法是为他们自己大多运行,但是有时通信通过共享存储器区域。不过,我想任务运行尽可能不受干扰。

The idea is for them to run mostly by themselves, but to sometimes communicate over a shared memory area. However, I want the tasks to run as undisturbed as possible.

推荐答案

您正在寻找的被称为线程亲和的概念。它是如何实现和接口要求它是操作系统相关的。

The concept you're looking for is called "thread affinity". How it's implemented and the interfaces to ask for it are OS-specific.

在Linux下,尝试了sched_setaffinity()。 glibc的还可以提供pthread_attr_setaffinity_np()。

Under Linux, try sched_setaffinity(). glibc may also offer pthread_attr_setaffinity_np().

这篇关于有没有办法到进程锁定到CPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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