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.

Posted on 2002-05-22 07:16:26 by Logan
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?
Posted on 2002-05-22 07:51:19 by C.Z.
It's something like this:

(save the value you get from rdtsc = a)

a few commands

(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 :)
Posted on 2002-05-22 07:59:30 by Logan
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.
Posted on 2002-05-22 08:01:42 by C.Z.
How will windows carry out all the behind the scenes tasks it needs to if your progam is hugging all processing time slots?
Posted on 2002-05-22 08:02:23 by MArtial_Code

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:
Posted on 2002-05-22 08:04:39 by C.Z.
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.
Posted on 2002-05-22 08:07:10 by Logan
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:
Posted on 2002-05-22 08:10:05 by C.Z.
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 :).
Posted on 2002-05-22 08:11:00 by f0dder
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
Posted on 2002-05-22 08:14:01 by Logan
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.
Posted on 2002-05-22 08:17:27 by C.Z.
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:
Posted on 2002-05-22 08:26:01 by bitRAKE

How will windows carry out all the behind the scenes tasks it needs to if your progam is hugging all processing time slots?
In fact, in Windows2000 DirectDraw & DirectSound won't work properly if one keeps REALTIME_PRIORITY_CLASS all the time.
Posted on 2002-05-22 08:28:52 by Maverick
What does it mean when a thread is starving?
Are there other descriptions for threads like starving
that I should know?
Posted on 2002-05-22 08:48:12 by Logan
starving == (the thread is schedulable) & (the thread is not executing at the moment)

For information on thread priority and scheduling, I suggest you buy Jeffrey Richter's Programming Applications for Windows.
Posted on 2002-05-22 09:03:41 by C.Z.