Check out this blog entry on fixing your timestep. Essentially the advice here is to use a loop where you draw as much as you can until a fixed threshold of time has passed, then update.
Here is the recommended game loop;
double t = 0.0;
double dt = 0.01;
double currentTime = hires_time_in_seconds();
double accumulator = 0.0;
State previous;
State current;
while ( !quit )
{
double newTime = time();
double frameTime = newTime - currentTime;
if ( frameTime > 0.25 )
frameTime = 0.25;
currentTime = newTime;
accumulator += frameTime;
while ( accumulator >= dt )
{
previousState = currentState;
integrate( currentState, t, dt );
t += dt;
accumulator -= dt;
}
const double alpha = accumulator / dt;
State state = currentState * alpha +
previousState * ( 1.0 - alpha );
render( state );
}
From a high level point of view, what is happening is that the loop is interpolating between the last state and the current state and then drawing as much as it can. Each pass accumulates more elapsed time. When this accumulated time is over the 0.01 threshold the system does a full state update.
So if a frame takes less than 0.01s to draw, we can expect >1 frame to be drawn for each update.
If, however, the last frame lagged and accumulated more than twice the dt then it will do 2 updates or more before the next draw. So when the system lags it will drop frames before it drops updates.
So this loop will, in essence, update essentially every 0.01s, but will draw as much as is possible.