Hyper Thriding in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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....
 
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 ?
 
Hi,

Out of curiosity, why you want to do that?

IMO it's better to let the OS handle these matters, the scheduler is who
should do that decision.

cheers,
 
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....

Take a look at the ProcessThread class and it's ProcessorAffinity property,
you can also use the IdealProcessor, but a I'm very curious why you ever
want to do this.

Willy.
 
I'm working on concurrency application, which runs tests simultaneously.
Those tests verify some modules in my company Chip (silicon).Sometimes we
need to run 2 tests which execute deferent modules in the chip, and we want
to be sure they are running in parallel at the same time, As all know one CPU
will not do that , so I want to be sure those 2 tests will run in deferent
thread in deferent CPUs, to have more coverage.
 
I'm working on concurrency application, which runs tests simultaneously.
Those tests verify some modules in my company Chip (silicon).Sometimes we
need to run 2 tests which execute deferent modules in the chip, and we want
to be sure they are running in parallel at the same time, As all know one CPU
will not do that , so I want to be sure those 2 tests will run in deferent
thread in deferent CPUs, to have more coverage.
 
I'm working on concurrency application, which runs tests simultaneously.
Those tests verify some modules in my company Chip (silicon).Sometimes we
need to run 2 tests which execute deferent modules in the chip, and we
want
to be sure they are running in parallel at the same time, As all know one
CPU
will not do that , so I want to be sure those 2 tests will run in deferent
thread in deferent CPUs, to have more coverage.

Right, while you might get a fair chance that the threads will be allocated
on the CPU set by the affinity mask, there is no strong guarantee it will
happen all the time, don't forget that the Windows OS is a general purpose
OS not a realtime OS, it's the OS scheduler who decides how it's threads are
scheduled and assined a CPU, NOT user code. Another thing I wan't to
mention, is that you should not expect that your two threads will
effectively run in paralell on two different CPU's if your system has only 2
CPU's available, there are more threads in the system (hundreds) and some
are running at higher priority than your user threads, when such a thread
wakes up it will remove your thread from a CPU and possibly flush it's
caches.
Another thing you should keep in mind is that the system itself assigns CPU
affinity for some of it's kernel threads (especially threads dealing with IO
requests and UI threads), you can easely watch this on a multi CPU box -
open taskman and look at the CPU usage history while moving the mouse very
rapidly, you will see that only CPU0 will ever be used.

Willy.
 
Willy Denoyette said:
Take a look at the ProcessThread class and it's ProcessorAffinity
property, you can also use the IdealProcessor, but a I'm very curious why
you ever want to do this.

Can't believe I forgot about those entirely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top