GNOME Bugzilla – Bug 644552
g_timeout_add_seconds(1, ...) may have a latency of up to 2 seconds
Last modified: 2011-03-12 19:07:23 UTC
If you call g_timeout_add_seconds (1, func, NULL); func may not be called until 2 seconds later (instead of one as one would expect). Ryan Lortie wrote on /timeout/seconds (tests/timeout.c): * We need a timeout of at least 2 seconds because * g_timeout_add_second can add as much as an additional second of * latency. This problem makes /timeout/rounding fail randomly, when the latency gets to 2 seconds. Note that all the subsequent calls to the function happen after 1 second. We should either fix this latency problem, or document it (and suggest g_timeout_add if that's an issue) and fix /timeout/rounding to not fail when this happens.
In fact g_timeout_add() already says: * If you want to have a timer in the "seconds" range and do not care * about the exact time of the first call of the timer, use the * g_timeout_add_seconds() function; this function allows for more * optimizations and more efficient system power usage. So we should document this on g_timeout_add_seconds and fix the test case. I'll cook a patch.
Created attachment 183206 [details] [review] patch
Review of attachment 183206 [details] [review]: I guess that makes sense. A little comment in the test case would be nice, explaining why we treat the first iteration differently.
Comment on attachment 183206 [details] [review] patch 89ca0f729665f812b142b9a107515c945237082a
Thanks, I've added a comment to the if clause of the test case and committed to master. Let me know if I can commit to 2.28.
Pushed 7fc46fa278922b29358845531eaff4b18cd8f035 to glib-2-28.