What cpu is my thread executing on?
-
Hello, I need to throttle a running thread based on the cpu usage that the thread is currently using. My main problem is that my machine has 4 cpu's and I don't know how to figure out which cpu my thread is executing on. (The other cpu's will be used for other queued thread work items, so I can't just look at total cpu usage.) My goal is to poll for cpu usage > 60 % on the current thread and then call thread.sleep until cpu usage returns below that level. I assume that I'll need to use a performance counter to do this. int processorInstance = 'need to figure out what to set this to.' System.Diagnostics.PerformanceCounter c = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", processorInstance.ToString()); Thanks, Brad
-
Hello, I need to throttle a running thread based on the cpu usage that the thread is currently using. My main problem is that my machine has 4 cpu's and I don't know how to figure out which cpu my thread is executing on. (The other cpu's will be used for other queued thread work items, so I can't just look at total cpu usage.) My goal is to poll for cpu usage > 60 % on the current thread and then call thread.sleep until cpu usage returns below that level. I assume that I'll need to use a performance counter to do this. int processorInstance = 'need to figure out what to set this to.' System.Diagnostics.PerformanceCounter c = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", processorInstance.ToString()); Thanks, Brad
I think there is a way to set the thread affinity (at least through Task Manager), not sure how it can be done programmatically. If it can be done in Task Manager, I don't see why it couldn't be done in a program...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
I think there is a way to set the thread affinity (at least through Task Manager), not sure how it can be done programmatically. If it can be done in Task Manager, I don't see why it couldn't be done in a program...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
I've worked around my problem for now with a well placed thread.sleep for now. Thread affinity looks like the right path to take though. Thanks for the advice.
-
I've worked around my problem for now with a well placed thread.sleep for now. Thread affinity looks like the right path to take though. Thanks for the advice.
Tune us all in if you find anything good :)
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon