std::future::wait_for example not producing any dots

When I select "Edit & Run" for the example given on the wait_for reference page and I run it on cpp.sh, I do not get any '.', which suggests to me the wait_for never times out.

Reference: http://www.cplusplus.com/reference/future/future/wait_for/

I have lowered the span from 100 ms to 1 ms and even 10 nanoseconds, and neither causes any '.' to be output.

My guess is the note given under the 'rel_time' parameter: 'Note that multi-threading management operations may cause certain delays beyond this' I'm assuming what is happening is that the calling thread isn't actually evaluating the wait_for result until after the async thread readies in this particular case and with this particular compiler. Even though the timeout interval has long since passed. Therefore the while loop doesn't even run one iteration. I have tried this example on another online compiler as well.

Is there an example that can guarantee the wait_for function returns std::future_status::timeout at least once when it is called?
I don't have the answer to your question, but I will note that the example works on my machine, but does not work on cpp.sh (The "Edit & Run" gear). So my guess would be it's some limitation of how the web interface works, or the fact that cpp.sh is sandboxed.
Last edited on
Runs under macOs Xcode and ideone online, but not coliru online.
Topic archived. No new replies allowed.