Open
Description
Bugzilla Link | 47074 |
Version | 10.0 |
OS | All |
Attachments | Test cases with sample findings for various versions |
CC | @mclow |
Extended Description
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.