<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - condition_variable::wait_for doesn't wait if duration is large"
   href="https://bugs.llvm.org/show_bug.cgi?id=47074">47074</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>condition_variable::wait_for doesn't wait if duration is large
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Standards Issues
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>greg@bond.id.au
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23833" name="attach_23833" title="Test cases with sample findings for various versions/OS">attachment 23833</a> <a href="attachment.cgi?id=23833&action=edit" title="Test cases with sample findings for various versions/OS">[details]</a></span>
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>