Hi
Under Win32, each thread is allocated a certain amount of cpu
time and then the environment for that thread is saved and the cpu loads the environment for the next thread and executes it...
Now how can I make my thread the only thread that is getting
cpu time? I used REALTIME_PRIORITY_CLASS or something like
that and it still looks to me that Win32 manage to execute
other threads in the time my thread is running.
My thread is a loop that executes for 5 seconds and
then exits, how can I prevent any other thread from executing
while my thread is busy.
This has to do with the rdtsc opcode which I use to see how
many cycles a certain loop takes to execute.
Regards
Under Win32, each thread is allocated a certain amount of cpu
time and then the environment for that thread is saved and the cpu loads the environment for the next thread and executes it...
Now how can I make my thread the only thread that is getting
cpu time? I used REALTIME_PRIORITY_CLASS or something like
that and it still looks to me that Win32 manage to execute
other threads in the time my thread is running.
My thread is a loop that executes for 5 seconds and
then exits, how can I prevent any other thread from executing
while my thread is busy.
This has to do with the rdtsc opcode which I use to see how
many cycles a certain loop takes to execute.
Regards
It's no likely that other threads will still be assigned cpu time when your realtime-priority thread is still starving.:confused:
Or did you make sure your code doesn't include any calls like Sleep() or GetMessage() and all?
And how did you know that it executes for 5 seconds?
Or did you make sure your code doesn't include any calls like Sleep() or GetMessage() and all?
And how did you know that it executes for 5 seconds?
It's something like this:
cpuid
rdtsc
(save the value you get from rdtsc = a)
a few commands
cpuid
rdtsc
(save the value you get from rdtsc = b)
Then 'a few commands' takes approx (b - a) cpu cycles .
But I don't want other threads to execute in between the
two rdtsc commands.
The 5 seconds was just a simple guess because I had a long
loop in the middle :)
cpuid
rdtsc
(save the value you get from rdtsc = a)
a few commands
cpuid
rdtsc
(save the value you get from rdtsc = b)
Then 'a few commands' takes approx (b - a) cpu cycles .
But I don't want other threads to execute in between the
two rdtsc commands.
The 5 seconds was just a simple guess because I had a long
loop in the middle :)
Use THREAD_PRIORITY_TIME_CRITICAL(for the thread) + REALTIME_PRIORITY_CLASS(for the process), which gives your thread the highest priority possible.
If there's no any other level-31 priority thread running, I'm sure your thread will get all cpu time till it's done.
If there's no any other level-31 priority thread running, I'm sure your thread will get all cpu time till it's done.
How will windows carry out all the behind the scenes tasks it needs to if your progam is hugging all processing time slots?
The 5 seconds was just a simple guess because I had a long
loop in the middle :)
Processors today are fast. It could be 0.5 seconds :tongue:
Hi bomb01, under Windows 98 this (31) seems to work,
but under Windows 2000 it seems that other threads
can still run. Maybe because the way NT works?
Martial_Code: Yes I know that is a rude thing to do to Windows,
but I only wanted to know if that was possible, if I have such
controlability over Windows... :)
Thanks for all your input.
but under Windows 2000 it seems that other threads
can still run. Maybe because the way NT works?
Martial_Code: Yes I know that is a rude thing to do to Windows,
but I only wanted to know if that was possible, if I have such
controlability over Windows... :)
Thanks for all your input.
MArtial_Code, what do you mean by "behind scene tasks"? If a thread with a level 31 priority keeps occupying the cpu(exclusively) for a long time, nothing really happens behind the scene. Only the computer freezes.:grin:
If you *really* need this, code a KMD and disable interrupts as well.
Usually you should be pretty fine just by fiddling with process/thread
priority... "even" timecritical enables you to mess up bigtime :).
Usually you should be pretty fine just by fiddling with process/thread
priority... "even" timecritical enables you to mess up bigtime :).
I've also noticed that if you use HREAD_PRIORITY_TIME_CRITICAL(for the thread) + REALTIME_PRIORITY_CLASS(for the process),
and your program got stuck in a loop, you can't CTRL-ALT-DELETE
and kill the process, you have to reset
:tongue:
and your program got stuck in a loop, you can't CTRL-ALT-DELETE
and kill the process, you have to reset
:tongue:
Logan, I think you should comply with MS's intention, as win32 is multi-tasking OS and the SDK can't include how the scheduler works for a certain windows version.
If you really want to time your code exclusively then you should use another OS. The windows philosophy is: if you want it to run faster then buy a faster processor. Nothing is meant to run exclusively - in fact it is designed to the contrary. :grin:
How will windows carry out all the behind the scenes tasks it needs to if your progam is hugging all processing time slots?
What does it mean when a thread is starving?
Are there other descriptions for threads like starving
that I should know?
Are there other descriptions for threads like starving
that I should know?
Logan:
starving == (the thread is schedulable) & (the thread is not executing at the moment)
:grin:
For information on thread priority and scheduling, I suggest you buy Jeffrey Richter's Programming Applications for Windows.
starving == (the thread is schedulable) & (the thread is not executing at the moment)
:grin:
For information on thread priority and scheduling, I suggest you buy Jeffrey Richter's Programming Applications for Windows.