如何在多核计算机上运行的C#点网络代码中使用硬件线程? [英] How to use hardware threads in C# dot net code running on multicore machine?

查看:104
本文介绍了如何在多核计算机上运行的C#点网络代码中使用硬件线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行在 多核 计算机上的C尖锐代码中使用 硬件线程 ?任何示例将不胜感激.

How to use hardware threads in C sharp code running on multi core machine ? Any example will be appreciated.

我希望在计算机的两个内核上并行运行两个线程 .如果我用C Sharp创建普通的软件线程,它们可能会在单核上运行.是否可以在两个内核上隐式并行运行这两个线程,以获得更好的性能?

I wish to run the two threads parallelly on two cores of my machine. If I create normal software threads in C sharp they may run on single core. Is it possible to run these two threads implicitly parallel on two cores so as to get better performance ?

推荐答案

您可能会看到处理器亲缘关系".

You may have a look at "Processor affinity".

您可以使用System.Diagnostics命名空间来强制进程在特定处理器上运行. 下一行将更改当前与处理器1和处理器1之间的关联性. 2

You can use System.Diagnostics namespace to force a process to run on a specific processor. The following line will change current process affinity to processors 1 & 2

System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)3;

Process.ProcessorAffinity属性 获取或设置可以安排运行该进程中的线程的处理器.

Process.ProcessorAffinity Property gets or sets the processors on which the threads in this process can be scheduled to run.

下表显示了两个处理器系统的ProcessorAffinity值的选择.

The following table shows a selection of ProcessorAffinity values for an two-processor system.

  Value   Description

    0   Not allowed
    1   Use processor 1
    2   Use processor 2
    3   Use both processors 1 and 2

有关更多详细信息,请阅读以下MSDN参考->

For more details please go through following MSDN reference--> http://msdn.microsoft.com/en-us/library/system.diagnostics.process.processoraffinity.aspx

这篇关于如何在多核计算机上运行的C#点网络代码中使用硬件线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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