[llvm-bugs] [Bug 47074] New: condition_variable::wait_for doesn't wait if duration is large

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 9 21:53:02 PDT 2020


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

            Bug ID: 47074
           Summary: condition_variable::wait_for doesn't wait if duration
                    is large
           Product: libc++
           Version: 10.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Standards Issues
          Assignee: unassignedclangbugs at nondot.org
          Reporter: greg at bond.id.au
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 23833
  --> https://bugs.llvm.org/attachment.cgi?id=23833&action=edit
Test cases with sample findings for various versions/OS

The following code should wait forever, but it does not, it returns
immediately:

#include <chrono>
#include <iostream>
#include <condition_variable>

using namespace std::chrono;

int main() {
    std::mutex m;
    std::unique_lock l(m);
    std::condition_variable cv;

    std::cout << "sleeping forever" << std::endl;
    cv.wait_for(l, milliseconds::max(), []() { return false; });
    std::cout << "returned!" << std::endl;
}


Tested on FreeBSD, Ubuntu16 & MacOS, clang version 6, 8 & 10

Behaviour is somewhat variable, depending on OS and compiler version (at least
for the small sample I have access to). Basically, given a duration past a
certain size (somewhere around 1<<52 units of any duration type), wait_for() no
longer waits at all.  On some versions/platforms, the 2-argument wait_for()
does not appear to wait at all, even for small durations.

This looks like some kind of overflow in the duration conversion.  

Bug filed under libraries, but problem may be in the compiler intrinsics.

See attached somewhat more detailed test cases and notes on the limits I have
discovered.

-- 
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/20200810/6c3b403a/attachment-0001.html>


More information about the llvm-bugs mailing list