Subj : Re: usage of time() for timeout handling To : comp.arch.embedded,comp.programming From : Bryan Hackney Date : Wed Jul 27 2005 03:50 pm David wrote: > Hi gurus, > I'm having some modules, that use time() for determine if a given activity > has timed out. As the operating system time will be updated periodically > with the time or the RTC chip, it is possible that the result of two calls > to time() would give a smaller value on the second call. This would cause > the timeout calculation to fail and result in unexpected behaviour. > This situation could specially occour if the user changed the time of the > system! How are you handling this problem? On could use the system tick for > timeout calculations. But somewhere I read that for acuracy reason you > should not do this for longer timeouts. How do you handle this problem? > > Thanks in adbance > David > > > If this is Linux, you can use uptime. There is no uptime system call, unfortunately, so I process /proc/uptime to get the information. Less than elegant, but I have had no problems doing this. Uptime continuously counts up since bootup. If this is Linux, please say so next time. The resolution of uptime is high, and the accuracy is good. .