Re: Time critical thread seems to pause briefly once every few seconds



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
.



Relevant Pages

  • Re: population sizes for colonising a planet
    ... > This is coming down to a basic matter of core priorities. ... > priority, ... than different areas of untouched nature. ...
    (rec.arts.sf.composition)
  • Re: [PATCH 2.6-git] SPI core refresh
    ... which SPI itself doesn't support. ... kernel threads with different priorities are working with two SPI controllers respectively *priority inversion* will happen. ... One controller is one thread, so it's _one_ priority, consequently there's nothing to invert. ... that the core is making me do things I think the core should do. ...
    (Linux-Kernel)
  • Re: Random weighted selection...
    ... negative priority jobs will accumulate to the head of the list and never get run. ... This by the way has the interesting property that no job will be kept waiting to execute longer than with a simple FIFO queue on a single-CPU machine of the same clock speed. ... They can be made to run immediately with added sophistication: for each job priority but the lowest there is a thread of proportional priority that consumes jobs of that priority from the queue and has affinity for one core; one more thread consumes jobs from the queue's head regardless of priority and has affinity for the other core. ... One way to fake it would be to implement jobs in a coroutine-style: they are Objects with a doABitMore() method that returns true when the job's done, and with the property that one invocation of doABitMoredoes very little. ...
    (comp.lang.java.programmer)
  • Re: Pentium I simulator
    ... There used to be lots of "slowdown" programs many years ago when old DOS ... want to slow down) would be running at its standard normal thread priority ... single processor / single core system, which is what you wanted to avoid, ... the point is that i wont be sure if it is emulating a Pentium 233 or ...
    (microsoft.public.vb.general.discussion)
  • Re: Pentium I simulator
    ... games were still popular and when running them on something like a P233 would have caused some of the games to run so fast as to be almost unusable. ... For example you could write a small VB program that ran some simple code in an endless closed loop, with some code in its Form Load event to set its thread priority to the highest value using the SetThreadPriority API. ... This of course would dramatically slow down everything else on the machine if it is a single processor / single core system, which is what you wanted to avoid, but since your own machine is dual core then this would not be too much of a problem because you could arrange for both your "slow the processor down" program and the program you are testing to be restricted to just one specific core. ... This could be different on different versions of Windows though, depending on how much of the processor time the OS allots to a high priority task compared to a normal priority task. ...
    (microsoft.public.vb.general.discussion)

Quantcast