c++c++11gcc4.8

C++11 std::this_thread::sleep_until() hangs when compiled with GCC 4.8.5


Consider the following program:

#include <chrono>
#include <thread>

int main() {
    std::this_thread::sleep_until(std::chrono::steady_clock::now() - std::chrono::seconds(10));

    return 0;
}

When compiled with GCC 4.8.5, it will hang. When compiled with GCC 4.9 and above or clang3.4 and above, it returns immediately,

Why would it hang? As I understand, GCC 4.8.5 fully supports C++11 standard.


Solution

  • This is a confirmed bug that was fixed in gcc 4.9.

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58038

    When using sleep_until() I get an bug with unsigned long scalar representations of a duration. If this duratoiin is in past, then you get an overflow in the length of the argument for sleep_for(). This causes an almost infinte sleep, instead of a fast return.