473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

time coversions and effect of time drift.

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

Dec 1 '05 #1
1 1061
Ram wrote:
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;
}

--
Thad

Dec 2 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: kwharrigan | last post by:
I am working on some code using python and a distributed system. Some particular message is sent on one machine (with a timestamp logged) and after the message is received, a timestamp is made. I...
7
by: WindAndWaves | last post by:
Hi Gurus Is it possible to display the time on a site using javascript. I want to show visitors the current time in New Zealand, but the javascript that I use actually displays the time on the...
5
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
2
by: Jason Priebe | last post by:
I'm a bit confused about SET TIME ZONE and its effect on PostgreSQL's date processing. In my experience with timestamps in all other *nix-based software systems, a timestamp is always a numeric...
38
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my...
4
by: __jakal__ | last post by:
Hello, I need to find out the time difference between UTC and local time. I am doing it the following way #include <sys/timeb.h> #include <stdio.h> int main() { struct timeb tp; ftime(&tp);
8
by: Fritz | last post by:
.... maybe now that it's a little clearer. Environment: Win Server 2003, :NET Framework 1.1, C# I have an application that polls on a web service method every time a timer event is raised. The...
33
by: ram.ragu | last post by:
hi i have problem to calculate idle time of cpu and if idle time is more then i have to shut down the system. can anyone tell me the idea to so that please
2
by: Nikola Skoric | last post by:
I have been trying to find appropriate way to do get local time in "yyyy-mm-dd hh:mm:ss" format, but the best I got is this: datetime.datetime.fromtimestamp(time.mktime(time.localtime())) It seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.