C#中的超级Thriding [英] Hyper Thriding in C#

查看:74
本文介绍了C#中的超级Thriding的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建新线程如下:

线程mThread =新线程(新ThreadStart(m_ClassThread.Go));

如何选择运行此线程的位置?

在我的系统中,我有2个进程设备,(CPU0和CPU1),我想要创建3

这些线程的线程2在CPU0中运行,最后一个在CPU1中,是否有任何方式来控制线程执行?
如何在特定的CPU中请求执行特定的

线程?

使用WMI我可以在我的系统中接收CPUs deviceID。但我不知道

如何控制....

解决方案


" [Yosi]" <哟** @ discussions.microsoft.com>在消息中写道

新闻:5C ********************************** @ microsof t.com ...

我创建新线程如下:
线程mThread =新线程(新ThreadStart(m_ClassThread.Go));
如何选择在哪里运行这个线程?
在我的系统中我有2个进程设备,(CPU0和CPU1),我想创建
3
线程2的那些线程在CPU0中运行而最后一个在CPU1,是否有任何控制线程执行的方法?如何在特定CPU中请求执行特定的线程?
使用WMI我可以在我的系统中接收CPUs deviceID。但我不知道如何控制....




你可以设置线程亲和力,排序。运行时不提供任何

支持,但您可以使用Windows SetThreadAffinity来确定

线程执行的位置。但是,运行时不会让一个线程确定一个线程将是一个文字系统线程,因此你无法安全地在所有

版本中执行此操作。在1.1中它应该是安全的,我不知道2.0。


我找不到有关SetThreadAffinity的完整信息,你可以通过一个好的

这个链接?,这不是C#功能我是否正确?

Daniel O''Connell [C#MVP]"写道:


" [Yosi]" <哟** @ discussions.microsoft.com>在消息中写道
新闻:5C ********************************** @ microsof t.com。 ..

我创建新线程如下:
线程mThread = new Thread(新ThreadStart(m_ClassThread.Go));
如何选择运行此线程的位置?
在我的系统中我有2个过程设备,(CPU0和CPU1),我想要创建
3
那些线程2在CPU0中运行,而最后一个在CPU1中运行,是<
有什么方法可以控制线程的执行?如何在特定CPU中请求执行特定的线程?
使用WMI我可以在我的系统中接收CPUs deviceID。但我不知道如何控制......



你可以设置线程亲和力,排序。运行时没有提供任何
支持,但您可以使用Windows SetThreadAffinity来确定
线程执行的位置。但是,运行时不会让一个线程始终是一个文字系统线程,因此你不能安全地在所有
版本中执行此操作。在1.1中它应该是安全的,我不知道2.0。





" [ Yosi] QUOT; <哟** @ discussions.microsoft.com>在消息中写道

新闻:B2 ********************************** @ microsof t.com ...

我找不到有关SetThreadAffinity的完整信息,你可以通过
好​​的链接吗?,这不是C#函数我是否正确?

Daniel O''Connell [C#MVP]"写道:


" [Yosi]" <哟** @ discussions.microsoft.com>在消息中写道
新闻:5C ********************************** @ microsof t.com。 ..

我创建新线程如下:
线程mThread = new Thread(新ThreadStart(m_ClassThread.Go));
如何选择运行此线程的位置?
在我的系统中我有2个进程设备,(CPU0和CPU1),我想
创建3
那些在CPU0中运行的线程2和CPU1中的最后一个,是<
有什么方法可以控制线程的执行?如何在特定CPU中请求执行特定的线程?
使用WMI我可以在我的系统中接收CPUs deviceID。但我不知道如何控制....



你可以设置线程亲和力,排序。运行时不提供任何
支持,但您可以使用Windows SetThreadAffinity来确定线程执行的
。但是,运行时没有让一个线程
始终是一个文字系统线程,因此你无法安全地在
所有版本中执行此操作。在1.1中它应该是安全的,我不知道2.0。




查看SetThreadAffinityMask

http://msdn.microsoft.com/library/de...lprocessor.asp


您需要通过PInvoke访问它。如果您需要它,请链接到下面的PInvoke教程

http://msdn.microsoft.com/library/de...keTutorial.asp


I create new thread as following:
Thread mThread = new Thread(new ThreadStart(m_ClassThread.Go));
How can I choose where to run this thread ?
In my system I have 2 Process devices ,(CPU0 and CPU1) , I want to create 3
Thread 2 of those thread to run in CPU0 and the last one in CPU1 , is there
any way to control threads execution ? How can I ask for execution specific
thread in specific CPU?
"Using WMI I can receive the CPUs deviceID in my system". But I don''t know
how to control....

解决方案


"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...

I create new thread as following:
Thread mThread = new Thread(new ThreadStart(m_ClassThread.Go));
How can I choose where to run this thread ?
In my system I have 2 Process devices ,(CPU0 and CPU1) , I want to create
3
Thread 2 of those thread to run in CPU0 and the last one in CPU1 , is
there
any way to control threads execution ? How can I ask for execution
specific
thread in specific CPU?
"Using WMI I can receive the CPUs deviceID in my system". But I don''t know
how to control....



You can set the thread affinity, sort of. The runtime doesn''t offer any
support but you can use the windows SetThreadAffinity to determine where the
thread executes. However, the runtime makes no gaurentee that a thread will
always be a literal system thread, thus you cannot safely do this across all
versions. In 1.1 it should be safe, I don''t know about 2.0.


I can''t find usfull information about SetThreadAffinity, can you past a good
link for this ?, It''s not C# function am I correct ?
"Daniel O''Connell [C# MVP]" wrote:


"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...

I create new thread as following:
Thread mThread = new Thread(new ThreadStart(m_ClassThread.Go));
How can I choose where to run this thread ?
In my system I have 2 Process devices ,(CPU0 and CPU1) , I want to create
3
Thread 2 of those thread to run in CPU0 and the last one in CPU1 , is
there
any way to control threads execution ? How can I ask for execution
specific
thread in specific CPU?
"Using WMI I can receive the CPUs deviceID in my system". But I don''t know
how to control....



You can set the thread affinity, sort of. The runtime doesn''t offer any
support but you can use the windows SetThreadAffinity to determine where the
thread executes. However, the runtime makes no gaurentee that a thread will
always be a literal system thread, thus you cannot safely do this across all
versions. In 1.1 it should be safe, I don''t know about 2.0.




"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...

I can''t find usfull information about SetThreadAffinity, can you past a good link for this ?, It''s not C# function am I correct ?
"Daniel O''Connell [C# MVP]" wrote:


"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...

I create new thread as following:
Thread mThread = new Thread(new ThreadStart(m_ClassThread.Go));
How can I choose where to run this thread ?
In my system I have 2 Process devices ,(CPU0 and CPU1) , I want to create 3
Thread 2 of those thread to run in CPU0 and the last one in CPU1 , is
there
any way to control threads execution ? How can I ask for execution
specific
thread in specific CPU?
"Using WMI I can receive the CPUs deviceID in my system". But I don''t know how to control....



You can set the thread affinity, sort of. The runtime doesn''t offer any
support but you can use the windows SetThreadAffinity to determine where the thread executes. However, the runtime makes no gaurentee that a thread will always be a literal system thread, thus you cannot safely do this across all versions. In 1.1 it should be safe, I don''t know about 2.0.



Check out SetThreadAffinityMask at

http://msdn.microsoft.com/library/de...lprocessor.asp

You''ll need to access it via PInvoke. Link to PInvoke tutorial below if you
need it

http://msdn.microsoft.com/library/de...keTutorial.asp


这篇关于C#中的超级Thriding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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