0

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?

Community
  • 1
  • 1
Frankie
  • 653
  • 1
  • 9
  • 20
  • 4
    In my experience some of stdlibc++ hasn't been completely up to date on 4.7 on x86, I imagine it is much worse on ARM. Have you tried boost::future? Possibly you are *using* std::future timeouts too early. – user3125280 Jan 19 '14 at 07:31
  • No, not yet. I am trying to limit our use of external libraries, esp. if there are (or should be) implementations in the standard libraries. – Frankie Jan 19 '14 at 07:37
  • The standard library is just a port of boost - it is possible that if the c++11 version doesn't work on your system, boost might. What status are they returning anyway? – user3125280 Jan 19 '14 at 07:39
  • The boost version on my board is 1.49 which does not have future support. With std the status values I get are ready and timeout (on ARM the wait_for call is basically non-blocking) – Frankie Jan 19 '14 at 07:55
  • If a boost version with futures is not available on your board, it might mean neither is a libstdc++. – user3125280 Jan 19 '14 at 07:57

1 Answers1

0

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.

Frankie
  • 653
  • 1
  • 9
  • 20