如何将手动线程或任务设置为核心之一 [英] how can set manual thread or task to one of core's

查看:130
本文介绍了如何将手动线程或任务设置为核心之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想将线程或任务设置为cpu的一个核心并在c#中对其进行管理?
粗略处理Process.GetCurrentProcess().ProcessorAffinity
请F1F1F1F1F1F1F1F1F1 !!!!!!!!!!!
thnx

hello
i want to set a thread or task to one core''s of cpu and manage it in c#?
of corse whitout Process.GetCurrentProcess().ProcessorAffinity
please F1F1F1F1F1F1F1F1 !!!!!!!!!!!
thnx

推荐答案

如果未设置处理器关联性,则不能.

除非您有非常具体的理由这样做并且知道陷阱,否则这也是一个坏主意.

这样的陷阱之一是,即使核心也忙于做其他事情而其他核心处于空闲状态,您也可以将代码限制在单个核心上运行.即使可能有可用的内核,您的代码也要等待.
Without setting processor affinity, you can''t.

It''s also a bad idea unless you have VERY SPECIFIC reasons for doing so and know the pitsfalls.

One such pitfall is that you limit your code to running on single core even if the core is also busy doing other things and other cores are idle. Your code gets to wait, even though there may be an available core.


除了进程亲和力之外,还有线程亲和力.

请查看我过去的答案:如何对多核进行编程 [
Except for process affinity, there is also a thread affinity.

Please see my past answer: How to program multicore[^].

Again, in agreement with Dave, don''t interfere in thread/process affinity unless you know exactly what are you doing!

—SA


这篇关于如何将手动线程或任务设置为核心之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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