How to make my program the highest priority
-
I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!
-
I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!
The
SetPriorityClass
function sets the priority class for the specified process. This value together with the priority value of each thread of the process determines each thread's base priority level. -
I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!
jinzhecheng wrote:
how to programmtically give your main thread the highest priority?
Why would you want to do this? It would all but totally disable the OS.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
jinzhecheng wrote:
how to programmtically give your main thread the highest priority?
Why would you want to do this? It would all but totally disable the OS.
"Take only what you need and leave the land as you found it." - Native American Proverb
Here is the reason: Say I am testing the speed (I/O reading writting). I want the Max performance , the code would be like: tStart = getCurrentTime(); do{ reading(); writting(); } span = getCurrentTime()- tSpan; How can I ensure those steps are not interupted?
-
Here is the reason: Say I am testing the speed (I/O reading writting). I want the Max performance , the code would be like: tStart = getCurrentTime(); do{ reading(); writting(); } span = getCurrentTime()- tSpan; How can I ensure those steps are not interupted?
The first thing to note is that
GetCurrentTime()
has been deprecated byGetTickCount()
. Second, callingSetThreadPriority()
with a priority greater than 11 may cause disk caches to not flush, hang the mouse, and so on.jinzhecheng wrote:
How can I ensure those steps are not interupted?
By using a
critical section
(e.g.,InitializeCriticalSection()
). I'm not sure you actually want to do this, however. If you are simply wanting to time a section of code,GetTickCount()
is the way to do this. Since Windows is not a RTOS, you'll not ever get 100% accuracy. For example, let's say that, per your watch, the code took 5 seconds to execute. However,span
had a value of 6000, or 6 seconds. That means that the code was preempted for a total of 1000 ms. This is not necessarily a bad thing. It's much like weighing yourself at home on a scale that is not 100% accurate. Whether it shows you to be too heavy or too light, it doesn't matter as long as it's consistent. By comparing one weigh with another from the same scale, you can judge for yourself whether you are gaining or losing weight. Make sense?
"Take only what you need and leave the land as you found it." - Native American Proverb