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 703594 - pthread_cond_timedwait() uses the realtime clock by default but gets monotonic clock time passed
pthread_cond_timedwait() uses the realtime clock by default but gets monotoni...
Status: RESOLVED DUPLICATE of bug 673607
Product: glib
Classification: Platform
Component: gthread
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-07-04 08:45 UTC by Sebastian Dröge (slomo)
Modified: 2013-07-05 14:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-gthread-Fix-g_cond_wait_until-for-systems-with-monot.patch (2.79 KB, patch)
2013-07-05 07:37 UTC, Sebastian Dröge (slomo)
none Details | Review

Description Sebastian Dröge (slomo) 2013-07-04 08:45:38 UTC
pthread_cond_timedwait() is using the realtime clock by default if it wasn't configured differently. At least on Android there is a monotonic clock but no pthread_condattr_setclock(). As a result g_cond_wait_until() is completely unreliable.

For Android this commit fixes it by using a different function:
https://git.gnome.org/browse/glib/commit/?id=dbdfcb69ce4a7f14bac784c2684c1a66bfe6a2c9

For some other platforms this might fix it too. I'm not sure if there are any others left that have a monotonic clock but no pthread_condattr_setclock(), but for those g_cond_wait_until() has to convert from monotonic clock to realtime clock before passing the time to pthread_cond_timedwait().

I could do a patch for this if there's any interest and people can think of platforms where this would be needed.
Comment 1 Allison Karlitskaya (desrt) 2013-07-04 14:20:13 UTC
Note: we have this:

#if defined (HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined (CLOCK_MONOTONIC)
  pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif
Comment 2 Allison Karlitskaya (desrt) 2013-07-05 04:21:07 UTC
As discussed on IRC, we should still solve the theoretical case where CLOCK_MONOTONIC is available, but not _setclock() and we don't have _timedwait_monotonic().
Comment 3 Sebastian Dröge (slomo) 2013-07-05 07:37:03 UTC
Created attachment 248435 [details] [review]
0001-gthread-Fix-g_cond_wait_until-for-systems-with-monot.patch
Comment 4 Dan Winship 2013-07-05 14:50:00 UTC
bug 673607 has an alternate patch for the same issue (and points out that this patch is racy)

*** This bug has been marked as a duplicate of bug 673607 ***