473,842 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7023
"kaiteriter i" <ka*********@di scussions.micro soft.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.Proces sorAffinity'
<URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfSystemDiag nosticsProcessC lassProcessorAf finityTopic.asp >

'ProcessThread. ProcessorAffini ty'
<URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfSystemDiag nosticsProcessT hreadClassProce ssorAffinityTop ic.asp>

'ProcessThread. IdealProcessor'
<URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfSystemDiag nosticsProcessT hreadClassIdeal ProcessorTopic. asp>

Determining the number of processors:

\\\
Imports System
..
..
..
.... = Environment.Get EnvironmentVari able("NUMBER_OF _PROCESSORS")
///

..NET 2.0: 'Environment.Pr ocessorCount'.

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

"kaiteriter i" 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*****@discus sions.microsoft .com> wrote in message
news:1E******** *************** ***********@mic rosoft.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.

"kaiteriter i" 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
1924
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
1645
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
4476
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 assuming that this is not an uncommon piece of software. I want to get an architecture that conforms as closely as possible with the recommendations from Microsoft on developing Windows Services, but to be honest I have found difficultly in...
3
5623
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 possible with .NET? Can't seem to find anything that would not include such support? API (aka unmanaged) solution? Thanks, Rob.
1
1961
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. -- Jeff S.
23
5727
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() { : : do stuff
2
1847
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 instance, run UI stuffs on processor #1 and run other background stuffs on processor #2. Possible?
10
2121
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 MyThread ( threading.Thread ): def run ( self ): myLongCommand()...
12
2084
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 background worker thread component. It has what you want built into it. http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
0
9872
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10945
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10612
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10314
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7858
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.