Re: Time critical thread seems to pause briefly once every few seconds
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 09 Jan 2008 09:46:18 -0800
On Wed, 09 Jan 2008 01:13:46 -0800, Joe Withawk <no@xxxxx> wrote:
I have an application in which there exist a thread that handles directx rendering. It runs on a dual core system with windows vista and xp.
It is set to have highest priority and simply loops with
while(isRendering)
{
prepare for rendering;
do render;
present()
}
[...]
Generally with two cores and few processes, I beleive the core running the critical thread will be more or less reserved for the thread and the other core will be uses for low priority work. Is this not correct?
That assumes that your thread is the only high priority thread on the computer. If there are enough high priority threads, they will all consume the available CPU cores and no lower priority thread will get to run (mostly).
Philosophically, I wouldn't call a rendering thread "time critical". "Time critical" is for things that, if you do not process them by some specific time something simply fails. Examples of this would be a thread servicing an unbuffered i/o port (or one with a very small buffer), such as reading from some kind of serial port, or writing data to an audio output device.
Even for a "time critical" thread, raising the priority is only appropriate if you know that the thread _must_ run when it's time for it to run, but it will finish quickly, never consuming its entire timeslice.
A rendering thread doesn't fall into that category.
It's difficult to say without having code to test, but...if I had to guess, I'd guess that your pausing is _because_ your thread has elevated priority. This isn't an appropriate approach anyway, but in this case I suspect that you are starving lower priority threads. But Windows doesn't let threads get completely starved. Eventually, they get a temporary priority boost until they're high enough to run.
At that point, a whole bunch of threads that have been starved for attention then get to do whatever it was that they wanted to do, and your high-priority thread gets to wait for them.
This will probably sound counter-intuitive, but the solution to your problem is likely to be to stop messing with the thread priority and leave your thread at normal priority. Or even to _lower_ the thread priority a bit. Lowering the priority, your thread will still get practically as much CPU time that it otherwise would have gotten, but the system will be much more user-responsive. It's a much more user-friendly way to write your code.
Bottom line: threads that don't block shouldn't be set to an elevated priority. If anything, they should have _lowered_ priority.
Pete
.
- Follow-Ups:
- Re: Time critical thread seems to pause briefly once every few seconds
- From: Joe Withawk
- Re: Time critical thread seems to pause briefly once every few seconds
- References:
- Time critical thread seems to pause briefly once every few seconds
- From: Joe Withawk
- Time critical thread seems to pause briefly once every few seconds
- Prev by Date: Re: profiler which does not just sum up used time
- Next by Date: Re: generic instantiation
- Previous by thread: Time critical thread seems to pause briefly once every few seconds
- Next by thread: Re: Time critical thread seems to pause briefly once every few seconds
- Index(es):
Relevant Pages
|