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

查看:46
本文介绍了有没有办法将进程锁定到 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天全站免登陆