time coversions and effect of time drift.

R

Ram

Hi,
I am looking for functions in 'C' to convert the struct timeval
into double,
add milliseconds to struct timeval.

Does anybody know how to do it.


What is the effect of "time drift" in time in linux. How can this be
taken care of ?.

Scenario ( )
{
StartTime = gettimeofday ( ) ;
PlayTime = StartTime + 2millseconds ;

while (1) {
Do Some Work ;

Now = gettimeofday ( ) ;

If (Now == PlayTime)
Play ( ) ;

PlayTime = Now + 2milliseconds ;
}

}

I Think Now and PlayTime will never be equal. I call this drift.


How does one take care ?.



Please Advice.

Any Pointers ?

Regards,
Ram
 
T

Thad Smith

Ram said:
Scenario ( )
{
StartTime = gettimeofday ( ) ;
PlayTime = StartTime + 2millseconds ;

while (1) {
Do Some Work ;

Now = gettimeofday ( ) ;

If (Now == PlayTime)
Play ( ) ;

PlayTime = Now + 2milliseconds ;
}

}

I Think Now and PlayTime will never be equal. I call this drift.

if (Now >= PlayTime)

assuming that Now and PlayTime don't overflow.

You can somewhat similar logic using fixed point timers that explicitly
do overflow:
unsigned int dif = PlayTime - Now;
if (dif > -MAX_LATENCY) {
play();
PlayTime += PLAY_INTERVAL;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top