Question

I have the following C++11 code:

auto f = std::async(std::launch::async, [] () { myfunction(); });
std::future_status status;
do {
    status = f.wait_for(std::chrono::seconds(1));
    if (status == std::future_status::timeout) {
        fprintf(stderr, "Hello!\n");
    }
} while (status != std::future_status::ready);

On my laptop this runs fine (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)), i.e. for every second myfunction() runs I get one "Hello!" output.

However on my ARM board with gcc version 4.7.3 20130328 (prerelease) (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) I get the output right away and without a significant delay (i.e. it does not wait even the first second), also it just keeps printing "Hello!" until myfunction() is finished.

According to http://en.cppreference.com/w/cpp/thread/future/wait_for I should only get the timeout status if and only if the timeout has expired.

I suspect this may be due to "Timed waiting functions do not return future_status::deferred" in GCC (ref. question C++ 11 future_status::deferred not working). However myfunction() runs, so eventually it should not return "Timeout" all the time, shouldn't it?

Does anybody have any experience with future::wait_for on ARM platforms, or does anybody could shed some light on this issue?

Was it helpful?

Solution

I updated the image on the board (from Ubuntu Raring to Ubuntu Saucy) and the code is now working fine. As @user3125280 indicated, this was in fact a stdlibc++ issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top