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 643795 - g_timeout_add_seconds fires with intervals 1 second longer than specified
g_timeout_add_seconds fires with intervals 1 second longer than specified
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-03 16:47 UTC by Mikael Magnusson
Modified: 2011-03-07 03:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
My "fix" (1.02 KB, patch)
2011-03-03 16:51 UTC, Mikael Magnusson
none Details | Review
possible patch (2.77 KB, patch)
2011-03-04 02:04 UTC, Matthias Clasen
none Details | Review

Description Mikael Magnusson 2011-03-03 16:47:34 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);
Comment 1 Mikael Magnusson 2011-03-03 16:51:09 UTC
Created attachment 182361 [details] [review]
My "fix"
Comment 2 Matthias Clasen 2011-03-04 02:04:34 UTC
Created attachment 182432 [details] [review]
possible patch
Comment 3 Mikael Magnusson 2011-03-04 07:31:33 UTC
(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)?
Comment 4 Matthias Clasen 2011-03-04 12:51:50 UTC
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.