Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:02:57+00:00 2026-06-12T14:02:57+00:00

It seems that unless you call std::async a std::future will never be set to

  • 0

It seems that unless you call std::async a std::future will never be set to any other state than future_status::deferred unless you call get or wait on the future. wait_for & wait_until will continue to not block and return future_status::deferred even if the task has already run and stored the result.

Here’s an example:

#include <future>

void main()
{
    auto func = []() { return 5; };
    auto asyncFuture = std::async(std::launch::async, func);
    auto status = asyncFuture.wait_for(std::chrono::seconds(0));   // timeout (1)

    auto deferredFuture = std::async(std::launch::deferred, func);
    status = deferredFuture.wait_for(std::chrono::seconds(0));     // deferred (2)

    std::packaged_task<int()> task(func);
    auto packagedTaskFuture = task.get_future();
    status = packagedTaskFuture.wait_for(std::chrono::seconds(0)); // deferred (2)

    task();

    status = packagedTaskFuture.wait_for(std::chrono::seconds(0)); // deferred (2)
    packagedTaskFuture.wait();
    status = packagedTaskFuture.wait_for(std::chrono::seconds(0)); // ready (0)
}

I don’t have the current C++11 standard, but the draft standard in 30.6.9 says that when a packaged_task is run it should store the result in the future’s shared state. It’s not very clear whether that includes setting the expected wait_until/wait_for behavior or not.

There were previously issues with VS11 behavior in this area with respect to async calls: http://social.msdn.microsoft.com/Forums/hu/parallelcppnative/thread/4394f2c1-0404-40df-869b-f4fc36fc035c

Additionally it seems like other compilers have problems in this area: C++ 11 future_status::deferred not working

Anyone that may know the standard better: Is this expected behavior or is there an issue with the implemenation in VS11?

Updates: I somehow missed the report for this: http://connect.microsoft.com/VisualStudio/feedback/details/761829/c-11-unexpected-behavior-for-std-future-wait-for-and-std-packaged-task

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:02:59+00:00Added an answer on June 12, 2026 at 2:02 pm

    This is an issue with VS2012. It’s not the only issue either — their implementation of the C++11 thread library has several bugs. I wrote about a few on my blog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that performing svn log gives me outdated information, unless I do an
Seems that This will be an easy question for you but this problem is
It seems that markers in an ItemizedOverlay are not shown in the map unless
It seems that JButton doesn't automatically receive the focus when clicked, unless I explicitly
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that we can show layers and even use a different zPosition for
It seems that runClasses() doesn't terminate the code being tested even after the test
It seems that JavaScript's Date() function can only return local date and time. Is
It seems that often I find that my code when moving either from one
It seems that it is not advisable to use <meta http-equiv=REFRESH CONTENT=3;url=url> for redirects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.