Re: Timeout timers in an application
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Mon, 21 Jan 2008 12:58:21 -0800 (PST)
On Jan 18, 9:27 am, "Ed J" <j...@xxxxxxxxxxx> wrote:
How can I implement a timeout timer in an application such that it wouldn't
be subject to a time-of-day clock adjustment? My current implementation
uses time(), etc., but since they are based on the time-of-day clock, my
code breaks if the system clock is set or adjusted while a timeout is
pending.
If your requirements are sufficiently complex to justify it, use a
full timer implementation that provides all of these features. If you
don't need particularly high resolution, just keep track of the system
uptime and the clock time and if you see that offset change, you'll
know the real time clock has been changed.
Generally, if you want to set a timer for 15 seconds from now, you
track that as being when the system uptime is 15 seconds more than it
was when the timer was set. Linux's CLOCK_MONOTONIC can be used for
this purpose.
If your application has its own 'uptime' tracking, you can use that.
DS
.
- Follow-Ups:
- Re: Timeout timers in an application
- From: Rainer Weikusat
- Re: Timeout timers in an application
- References:
- Timeout timers in an application
- From: Ed J
- Timeout timers in an application
- Prev by Date: Re: RS232 Redirector Program in C using Linux
- Next by Date: Re: RS232 Redirector Program in C using Linux
- Previous by thread: Re: Timeout timers in an application
- Next by thread: Re: Timeout timers in an application
- Index(es):
Relevant Pages
|