Re: Repeated timeouts period

Le primidi 21 vendémiaire, an CCXIV, Ben Johnson a écrit :
>		     what's more difficult is making one that saves the
> api user any time or trouble.

Yes, you are precisely right. The hardest part is in fact to find an API to
select what to do when it is not possible to hold the delay. That is why I
wonder if I should think to the question and try to give an answer somewhat
suitable for the community, or just write what I need in my app and do not

> you've already given a pretty good example of how to deal with this
> problem properly.  something like: use the timeout to fetch the real
> system time once every 999/1000's of a second.

No, you are making a mistake here: having a 999ms timeout has just the same
problem as having a 1000ms timeout: sooner or later, your timeout will fall
in a pattern like that:

time = 42.0003 -> clock updated to 42
time = 42.9998 -> clock left to 42
time = 43.9993 -> clock updated to 43, almost 1 second late
time = 44.9988 -> clock updated to 44, almost

One could round instead of truncating, but that leave up to half a second
error, which do not suite me.

Le primidi 21 vendémiaire, an CCXIV, Tristan Van Berkom a écrit :
>     Using an event based mainloop like GTK+; which as you noted, simply
> isn't designed for perfect accuracy; there will obviously always be
> a divergence between the "remaining seconds" and the value displayed
> in the "remaining seconds" GtkLabel; that being said, is there anything
> wrong with running a timeout function about 10 times every second and
> updating the "remaining seconds" label only when needed ?

Careful (and indeed, not very complex) programming can reduce the divergence
to the intrinsic system latency, which is less than 1/100s on a recent idle
Linux box. The solution with a 1/10s timeout gives ten times less accuracy,
for ten times more CPU. Even if no one would ever notice the difference, I
do not want that in my programs, for aesthetic reasons.

If no one else has that whim, well, sorry to have spent your time :-)

Attachment: signature.asc
Description: Digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]