After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 644552 - g_timeout_add_seconds(1, ...) may have a latency of up to 2 seconds
g_timeout_add_seconds(1, ...) may have a latency of up to 2 seconds
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: mainloop
2.28.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-03-12 09:44 UTC by Emilio Pozuelo Monfort
Modified: 2011-03-12 19:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (1.65 KB, patch)
2011-03-12 10:13 UTC, Emilio Pozuelo Monfort
committed Details | Review

Description Emilio Pozuelo Monfort 2011-03-12 09:44:50 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.
Comment 1 Emilio Pozuelo Monfort 2011-03-12 10:01:35 UTC
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.
Comment 2 Emilio Pozuelo Monfort 2011-03-12 10:13:33 UTC
Created attachment 183206 [details] [review]
patch
Comment 3 Matthias Clasen 2011-03-12 14:19:53 UTC
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 4 Emilio Pozuelo Monfort 2011-03-12 15:55:17 UTC
Comment on attachment 183206 [details] [review]
patch

89ca0f729665f812b142b9a107515c945237082a
Comment 5 Emilio Pozuelo Monfort 2011-03-12 15:56:00 UTC
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.
Comment 6 Emilio Pozuelo Monfort 2011-03-12 19:07:23 UTC
Pushed 7fc46fa278922b29358845531eaff4b18cd8f035 to glib-2-28.