GNOME Bugzilla – Bug 703594
pthread_cond_timedwait() uses the realtime clock by default but gets monotonic clock time passed
Last modified: 2013-07-05 14:50:00 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.
Note: we have this: #if defined (HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined (CLOCK_MONOTONIC) pthread_condattr_setclock (&attr, CLOCK_MONOTONIC); #endif
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().
Created attachment 248435 [details] [review] 0001-gthread-Fix-g_cond_wait_until-for-systems-with-monot.patch
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 ***