Do we need to schedule threads to diff processors?
-
Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini
-
Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini
-
Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini
if memory serves me correctly Task Class[^] and Parallel.ForEach[^] are optimised to handle the cores of a processor better than
Threading
class orthreadpool
. But you haven't really given much information to help us give you a better answer.Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini
One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance. You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago! Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre. Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
-
One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance. You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago! Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre. Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
Quote:
You can't force a thread onto an processor,
I'm not claiming any expertise on this subject and have no idea why one would wish to do this. But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question). Once you have the needed ProcessThread, you could set its processor affinity[^] property.
-
Quote:
You can't force a thread onto an processor,
I'm not claiming any expertise on this subject and have no idea why one would wish to do this. But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question). Once you have the needed ProcessThread, you could set its processor affinity[^] property.
TnTinMn wrote:
I'm not claiming any expertise on this subject and have no idea why one would wish to do this.
Attempting to improve performance, I'd guess. Still, Windows will halt the thread from time to time, and while one can set an affinity, one can not claim a specific core. that's a good thing
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Good one i see your link