[llvm-bugs] [Bug 39489] New: libc++ condition variables should use a steady clock

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 29 13:31:34 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39489

            Bug ID: 39489
           Summary: libc++ condition variables should use a steady clock
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: danalbert at google.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Refiling from an internal bug on behalf of tomcherry@:

libc++ condition variables have two issues with regards to how they wait with
timeout.

1) wait_for() takes a relative timeout and as per section 30.2.4.3, this
timeout should be measured with a steady clock: "The member functions whose
names end in _for take an argument that specifies a duration. These functions
produce relative timeouts. Implementations should use a steady clock to measure
time for these functions."

However, this is not the case.  These condition variables are implemented on
top of pthread condition variables and use the default initialization, which
uses CLOCK_REALTIME for all timeouts.  This clock is liable to change if the
user changes time on the device and this will cause early or delayed timeouts. 
Delayed timeouts have caused real bugs in Android.

2) wait_until() takes an absolute timeout and as per section 30.2.4.4, this
timeout should be measured with the clock specified in the timeout parameter to
the function, e.g. steady_clock (CLOCK_MONOTONIC) or system_clock
(CLOCK_REALTIME): "The member functions whose names end in _until take an
argument that specifies a time point. These functions produce absolute
timeouts. Implementations should use the clock specified in the time point to
measure time for these functions."

This is also not the case.  Unfortunately, this is not possible to do with the
pthreads API.  It is, however, possible if the pthreads API is avoided and
libc++ implements these condition variables directly with the futex system
call.

Tom also uploaded a change drafting the fix for this:
https://reviews.llvm.org/D44945. Spoke with Eric about this and there's still
some work that needs to be done, so this serves as a tracking bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181029/a6ef71e1/attachment.html>


More information about the llvm-bugs mailing list