473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How do you force a thread to run on a specific processor?

I have a time-consuming VB.net application that i'd like to thread over
2 processors (that's all i've got in my machine!) and, hopefully, get it
done in
half the time. On running, the application should create a 2nd thread and run
it on the other processor (processing a distinct set of data), leaving the
current
thread to run and process its set of data. But the 2nd thread must run on the
free processor, otherwise there's no point...

Can someone point me towards a VB.net example that does this?

{I see mention elsewhere of Get/Set of AffinityMasks within Threads but not
any examples of its usage for this type of thing, I believe this is the
property
that is used to force a specific processor to be used.}
Nov 21 '05 #1
4 7002
"kaiteriteri" <ka*********@discussions.microsoft.com> schrieb:
I have a time-consuming VB.net application that i'd like to thread over
2 processors (that's all i've got in my machine!) and, hopefully, get it
done in
half the time. On running, the application should create a 2nd thread and
run
it on the other processor (processing a distinct set of data), leaving the
current
thread to run and process its set of data. But the 2nd thread must run on
the
free processor, otherwise there's no point...


Some links on this topic:

'Process.ProcessorAffinity'
<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassProcessorAffinit yTopic.asp>

'ProcessThread.ProcessorAffinity'
<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessThreadClassProcessorA ffinityTopic.asp>

'ProcessThread.IdealProcessor'
<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessThreadClassIdealProce ssorTopic.asp>

Determining the number of processors:

\\\
Imports System
..
..
..
.... = Environment.GetEnvironmentVariable("NUMBER_OF_PROC ESSORS")
///

..NET 2.0: 'Environment.ProcessorCount'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
I don't think you have to do anything special to get what you want. If you
have two processors and you launch a second thread, windows will efficiently
allocate threads to processers. It will do so if your 2-thread program is
all that is running or if your 2-thread program runs concurrently with other
cpu hungry programs.

"kaiteriteri" wrote:
I have a time-consuming VB.net application that i'd like to thread over
2 processors (that's all i've got in my machine!) and, hopefully, get it
done in
half the time. On running, the application should create a 2nd thread and run
it on the other processor (processing a distinct set of data), leaving the
current
thread to run and process its set of data. But the 2nd thread must run on the
free processor, otherwise there's no point...

Can someone point me towards a VB.net example that does this?

{I see mention elsewhere of Get/Set of AffinityMasks within Threads but not
any examples of its usage for this type of thing, I believe this is the
property
that is used to force a specific processor to be used.}

Nov 21 '05 #3
I would agree. Some months ago, I was actually preparing to do the same
thing (assigning threads to CPUs). I wrote all of the code to check the
number of CPUs, setup a realtime graph that shows the load for each
processor that's available (engineers love pretty graphs, espcially when
they move!), and was in the process of writing an algorithm to balance the
CPU load (at least for the threads in my app), when I noticed that the OS
does a reasonable job of balancing the load automatically.

I was actually happy to stop work on the balancing algorithm, because I was
having trouble getting my head around how to move an active thread from one
processor to another processor if the user started other CPU intensive apps
that I had no control over.

HTH
Lee

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
I don't think you have to do anything special to get what you want. If you
have two processors and you launch a second thread, windows will
efficiently
allocate threads to processers. It will do so if your 2-thread program is
all that is running or if your 2-thread program runs concurrently with
other
cpu hungry programs.

"kaiteriteri" wrote:
I have a time-consuming VB.net application that i'd like to thread over
2 processors (that's all i've got in my machine!) and, hopefully, get it
done in
half the time. On running, the application should create a 2nd thread and
run
it on the other processor (processing a distinct set of data), leaving
the
current
thread to run and process its set of data. But the 2nd thread must run on
the
free processor, otherwise there's no point...

Can someone point me towards a VB.net example that does this?

{I see mention elsewhere of Get/Set of AffinityMasks within Threads but
not
any examples of its usage for this type of thing, I believe this is the
property
that is used to force a specific processor to be used.}

Nov 21 '05 #4


thx, i will try running multiple copies and see how i get on
before delving into the innards...

(thx to Herfried for the disection details...)
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ola Natvig | last post by:
Anybody out there who knows if the 4suite implementation of XSLT are a threadsafe one? -- -------------------------------------- Ola Natvig <ola.natvig@infosense.no> infoSense AS / development
1
by: Christoph | last post by:
Hi, I hope you can help me: I'd like to determine the processor on which a specified thread is running. THX, Christoph
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
3
by: Rob R. Ainscough | last post by:
Is it possible to assign threads to a specific CPU ID? I'm attempting to provide performance benefits for 2 and 4 CPU systems and would like to assign specific threads to a processor, is this...
1
by: Object01 | last post by:
Is there a way to determine which processor a thread is or was running on at a specific point in time? I want to examine patterns in how the thread scheduler assigns waiting threads to processors....
23
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() {...
2
by: Jon B | last post by:
Hi There! We have 2 processor server (Not dual core, actual seperate processors). Is it possible from .NET to force some threads to run on certain processor (say on processor #2)? For...
10
by: sophie_newbie | last post by:
Hi, I'm trying to write a piece of code that spawns a thread and prints dots every half second until the thread spawned is finished. Code is something like this: import threading class...
12
by: Ronny | last post by:
Thanks Chris, Looks nice but I miss the dual way communication. In the main thread to deliver paramters and data to the worker thread- how can I do that? Regards Ronny Take a look at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.