GNOME Bugzilla – Bug 643795
g_timeout_add_seconds fires with intervals 1 second longer than specified
Last modified: 2011-03-07 03:38:41 UTC
When I do g_timeout_add_seconds(1, (GSourceFunc)timer_timeout, t); in glib 2.26, it fires once per second, with 2.28 it fires every second second. If I pass 0, it fires very often in 2.26, every second in 2.28, and so on. The problem is located in the g_timeout_set_expiration() function I think. I tried comparing it with the 2.26 code, but I couldn't figure anything out. The only way I could fix it was to replace the whole logic with timeout_source->expiration += timer_perturb - (timeout_source->expiration % 1000000);
Created attachment 182361 [details] [review] My "fix"
Created attachment 182432 [details] [review] possible patch
(In reply to comment #2) > Created an attachment (id=182432) [details] [review] > possible patch Wouldn't this patch cause the timeout to fire lots of times in a row if one callback took more than one second (once for each second it missed)?
I seriously hope your callback does not take more than one second. And if it does, you better not schedule it to run once a second... but joking aside, yes, the patch is not perfect, it was mainly meant to illustrate the source of the problem.