473,396 Members | 1,895 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,396 software developers and data experts.

threading choice on single/multiple CPU

Just recently, I happened came across one .net multithreading book saying
that multithread programs might get differential in stability when running
on single CPU machine compared to a multi-CPU one.The book also recommands a
way in .NET to run specific thread on specific CPU.

Now I am facing a new project which is going to be deployed to either a
single or a multiple CPU machine. My problem is: can .NET 'automatically'
detect CPU status and distribute threads created by my program to all the
installed CPUs, in other words, without 'manually' set in the program for
the thread to be specific CPU centric, can a multithreaded program fully
utilized the CPU resources provided by the system?

I am quite confused about that, could anyone of you give me some advice,
thanks and appreciated.
Nov 16 '05 #1
5 4590
Tommy <to***@kaiyunzhu.net> wrote:
Just recently, I happened came across one .net multithreading book saying
that multithread programs might get differential in stability when running
on single CPU machine compared to a multi-CPU one.The book also recommands a
way in .NET to run specific thread on specific CPU.
What exactly do you mean by "differential in stability"?

Certainly there are multi-threading bugs which you probably won't
notice if you're only running on a single CPU - but if your code is
properly written, it shouldn't become unstable on multiple CPUs. You
shouldn't need to run specific threads on specific CPUs.
Now I am facing a new project which is going to be deployed to either a
single or a multiple CPU machine. My problem is: can .NET 'automatically'
detect CPU status and distribute threads created by my program to all the
installed CPUs, in other words, without 'manually' set in the program for
the thread to be specific CPU centric, can a multithreaded program fully
utilized the CPU resources provided by the system?

I am quite confused about that, could anyone of you give me some advice,
thanks and appreciated.


It automatically distributes them - at least, I believe it's the OS
that does it rather than .NET itself. I don't know whether threads can
migrate from one CPU to another though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi Tommy,
Just recently, I happened came across one .net multithreading book saying
that multithread programs might get differential in stability when running
on single CPU machine compared to a multi-CPU one.The book also recommands a way in .NET to run specific thread on specific CPU.
You have to be more specific on this. Exactly what the sugest? .NET has
some improved support for threading API (like ThreadPool ) that older MS OS
versions didn't support, or support but through some not
well-documented/not-so-common APIs, like IOCP. Because of that most
programmers usually code they're thread in a fire-and-forget behavior, wich
is not a good aproach if you're doing,for example, server applications.
However, as Jon stated before, once the thread is created, it is a
thread that's all. from an OS, or processor, perspective any thread will
behave the same way.
Now I am facing a new project which is going to be deployed to either a
single or a multiple CPU machine. My problem is: can .NET 'automatically'
detect CPU status and distribute threads created by my program to all the
installed CPUs, in other words, without 'manually' set in the program for
the thread to be specific CPU centric, can a multithreaded program fully
utilized the CPU resources provided by the system?


Yes, this could happen, but because of .NET. the Windows 2000/XP/2003
and others do that. This is a OS task, not .NET task, and there is no other
way to be done. Once there is threads started, the OS should, at some point,
allow the thread to be acessed by the processor to be processed :).
If you have thread dependencies that impose a situation where one thread
should be performed after other thread job, you should by some how
synchronize them, suspending the dependent thread execution until the other
thread signal that it completes it's job.
Being "CPU centric" means that you buy a $$$ hardware with 4 processors,
but will keep 3 of them unused, right?
For curios, in which book you see that? Is this a "good practice"
recomendetion from it?

Cheers,

Eric
Nov 16 '05 #3
It automatically distributes them - at least, I believe it's the OS
that does it rather than .NET itself. I don't know whether threads can
migrate from one CPU to another though...

--

They can even though it incurs the hit of having the load the cache for that
CPU rather then run on a warm cache on the same CPU. Using Win32 API's it's
possible to set thread affinity but that's not exposed in .NET (nor should
it be) since it is non-portable. Besides, the OS can usually make better
decisions about which CPU to run a thread on than an application.
Nov 16 '05 #4
thx guys for your post.
The book I am refering is manning's '.net multithreading'
and the .NET do provide a way to specify thread to a
target CPU. It's through ProcessThread.IdealProcessor
Property.
Anyway, I think I can draw the following conclusion of
this question:
system will manage threads created by .NET program and
only reason to improve the performance by mannually set
thread to be running on a specific CPU is because of the
improvement of CPU cache hit.
Am I right
-----Original Message-----
Just recently, I happened came across one .net multithreading book sayingthat multithread programs might get differential in stability when runningon single CPU machine compared to a multi-CPU one.The book also recommands away in .NET to run specific thread on specific CPU.

Now I am facing a new project which is going to be deployed to either asingle or a multiple CPU machine. My problem is: can .NET 'automatically'detect CPU status and distribute threads created by my program to all theinstalled CPUs, in other words, without 'manually' set in the program forthe thread to be specific CPU centric, can a multithreaded program fullyutilized the CPU resources provided by the system?

I am quite confused about that, could anyone of you give me some advice,thanks and appreciated.
.

Nov 16 '05 #5
On Wed, 14 Jul 2004 06:39:19 -0700, "Tommy"
<an*******@discussions.microsoft.com> wrote:
Anyway, I think I can draw the following conclusion of
this question: system will manage threads created by
.NET program and only reason to improve the performance
by mannually set thread to be running on a specific CPU
is because of the improvement of CPU cache hit.
Am I right?


On a shared memory multiprocessor, load operations are typically
extended to include checking the caches of the other CPUs. There is a
slight reduction in performance when code or data must migrate from
one cache to another, but migration is still much faster than loading
anything from RAM.

Keep in mind that migration is performed incrementally as the code
executes - just like all other cache operations. The CPU that
previously executed the thread will go on about it's business and may
displace the thread's data from it's cache before that data can be
migrated to the thread's current CPU.

In an active system with many runnable threads it usually makes no
difference which CPU executes a thread because it is likely that all
of the thread's code and data will be displaced before the thread is
scheduled to run again.

George
--
for email reply remove "/" from address
Nov 16 '05 #6

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

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
4
by: Joe Wong | last post by:
Hi, Is there any way to increase/decrease a thread priority in Python? Best regards, -- Wong
13
by: Varun | last post by:
Hi Friends, Department of Information Technology, Madras Institute of Technology, Anna University, India is conducting a technical symposium, Samhita. As a part of samhita, an Online Programming...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Tommy | last post by:
Just recently, I happened came across one .net multithreading book saying that multithread programs might get differential in stability when running on single CPU machine compared to a multi-CPU...
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
7
by: Chris Dunaway | last post by:
Suppose I have several threads that need to access the same object. ThreadA successfully acquires the lock using SyncLock. ThreadB attempts to acquire the lock and blocks and then ThreadC attempts...
6
by: Fred Exley | last post by:
Just trying to understand the basics here. If the OS has just one CPU, what advantage is there in threading? thanks
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.