Re: Thread deadlock misery



The real error is not in the GetTickCount() overflow. It's safe to calculate
elapsed time by subtracting it. It's NOT safe to just compare it.

The real error is that dwSleepTime is NEVER negative. If the execution is
behind, dwSleepTime is very big positive number, and the thread will sleep
pretty much forever.

"Ben Voigt" <rbv@xxxxxxxxxxxxx> wrote in message
news:O3SSkjYZHHA.3272@xxxxxxxxxxxxxxxxxxxxxxx
InterlockedIncrement( &pParent->m_nSentFrames );
DWORD dwSleepTime = ( 1000 / pATFP->TFP.FPS ) -
( GetTickCount() - dwStartTime );
if( dwSleepTime > 0 )
Sleep( dwSleepTime );

What happens when GetTickCount() overflows back to zero? Also, you're
accounting for the delay in your processing, but not the variation in
Sleep times, so your overall transmit rate is lower than you think. Use a
waitable timer instead.



.



Relevant Pages

  • Re: Environment.TickCount - can I trust the documentation?
    ... > The documentation states that Environment.TickCount is a signed integer ... Environment.TickCount and didn't find code like "GetTickCount() & ... > I want to measure elapsed time in a server application which will, I hope, ... the Environment class to measure elapsed ticks. ...
    (microsoft.public.dotnet.framework)
  • Re: calculating run time for portions of code
    ... ColdFusion, there is the function gettickcount(), and you would do ... set starttime = gettickcount ... set endtime = gettickcount ... You can't get the run time, you can get the elapsed time. ...
    (comp.lang.tcl)
  • Re: gettickcount returns a negative number???
    ... Platform SDK: Windows System Information - GetTickCount ... "The elapsed time is stored as a DWORD value. ...
    (microsoft.public.vb.winapi)
  • Re: CTime
    ... How About [GetTickCount] api ... Alok Gupta ... > I'd like to calculate elapsed time. ...
    (microsoft.public.vc.mfc)