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 527214 - g_timer_elapsed() returns random values
g_timer_elapsed() returns random values
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gthread
2.14.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-04-09 19:31 UTC by Mathias Hasselmann (IRC: tbf)
Modified: 2011-10-04 21:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Bug 527214 – g_timer_elapsed() returns random values. (2.20 KB, patch)
2008-04-09 20:05 UTC, Mathias Hasselmann (IRC: tbf)
committed Details | Review
gtimer: remove warnings about threads (1.05 KB, patch)
2011-10-04 21:18 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Mathias Hasselmann (IRC: tbf) 2008-04-09 19:31:54 UTC
GTimer uses internal uses GThread API (g_thread_gettime()) and therefore fails, when the thread system is not initialized yet. The API documention doesn't mention this requirement.

The API docs should mention this requirement, and g_timer_new() should warn if the thread system is not initialized yet.
Comment 1 Mathias Hasselmann (IRC: tbf) 2008-04-09 20:05:16 UTC
Created attachment 108953 [details] [review]
[PATCH] Bug 527214 – g_timer_elapsed() returns random values.


* glib/gtimer.c (g_timer_new()):
  Print warning if g_thread_init() has not been called yet.
---
 ChangeLog                            |    7 +++++++
 docs/reference/ChangeLog             |    7 +++++++
 docs/reference/glib/tmpl/timers.sgml |    7 +++++++
 glib/gtimer.c                        |    4 ++++
 4 files changed, 25 insertions(+), 0 deletions(-)
Comment 2 Matthias Clasen 2008-05-15 06:49:06 UTC
Good catch. The patch looks fine to me. Might be a case for g_warn_if_fail ?
Comment 3 Matthias Clasen 2008-05-18 19:16:51 UTC
        Bug 527214 – g_timer_elapsed() returns random values.

        * glib/gtimer.c (g_timer_new()):
        Print warning if g_thread_init() has not been called yet.
        Patch by Mathias Hasselmann
Comment 4 Richard Hult 2008-05-25 08:40:36 UTC
Hm, I might be missing something, but it looks like g_thread_gettime does nothing related to threads at all... it just runs gettimeofday and returns the result.

The only time you really need to init threads for gtimer is when you don't have nanosleep/nsleep, as far as I can see?
Comment 5 Matthias Clasen 2008-05-27 15:29:29 UTC
Yeah, I think I was too quick in accepting that patch. g_thread_gettime is supposed to work without threads. It should just work better when threads are enabled.
Comment 6 Matthias Clasen 2008-05-27 15:50:46 UTC
Mathias, what 'random values' were you seeing ?

One problem could be if you start a timer before initializing the threads, and then stop it afterwards, because initializing threads changes the gettime implementation. 

Comment 7 Allison Karlitskaya (desrt) 2011-10-04 21:18:22 UTC
Created attachment 198258 [details] [review]
gtimer: remove warnings about threads

GTimer no longer uses the thread system for time information and
g_thread_init() no longer does anything, so remove the doubly-untrue
warning about these topics.