C++ std::future在使用std::packaged_任务(VS11)时仍然延迟

C++ std::future在使用std::packaged_任务(VS11)时仍然延迟,c++,c++11,visual-studio-2012,future,packaged-task,C++,C++11,Visual Studio 2012,Future,Packaged Task,似乎除非调用std::asyncastd::future将永远不会被设置为除future\u status::deferred之外的任何其他状态,除非调用get或waitwait_for&wait_until将继续不阻塞并返回future_status::deferred,即使任务已经运行并存储了结果 下面是一个例子: #include <future> void main() { auto func = []() { return 5; }; auto async

似乎除非调用
std::async
a
std::future
将永远不会被设置为除
future\u status::deferred
之外的任何其他状态,除非调用
get
wait
wait_for
&
wait_until
将继续不阻塞并返回
future_status::deferred
,即使任务已经运行并存储了结果

下面是一个例子:

#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)
}
#包括
void main()
{
auto func=[](){return 5;};
auto-asyncfourture=std::async(std::launch::async,func);
auto status=asyncFuture.wait_for(std::chrono::seconds(0));//超时(1)
auto-deferredFuture=std::async(std::launch::deferred,func);
status=deferredFuture.等待(std::chrono::seconds(0));//延迟(2)
std::打包任务(func);
auto-packagedTaskFuture=task.get_future();
status=packagedTaskFuture.wait_for(std::chrono::seconds(0));//延迟(2)
任务();
status=packagedTaskFuture.wait_for(std::chrono::seconds(0));//延迟(2)
packagedTaskFuture.wait();
status=packagedTaskFuture.wait_for(std::chrono::seconds(0));//就绪(0)
}
我没有当前的C++11标准,但是30.6.9中的标准草案说,当运行
打包的_任务时,它应该将结果存储在未来的共享状态中。目前还不清楚这是否包括设置预期的
等待
/
等待
行为

以前,VS11在这方面的行为在
async
调用方面存在问题:

此外,似乎其他编译器在这方面也存在问题:

任何可能更了解该标准的人:这是预期行为还是VS11中的实现存在问题


更新:不知何故,我错过了这方面的报告:

这是VS2012的问题。这也不是唯一的问题——他们对C++11线程库的实现有几个bug。我写了一些。

谢谢!我知道VS11C++11STL支持不是很好,但我不认为它会完全无法使用。对boost实现这些功能(显然不是异步的或它们还没有实现的东西)有什么评论吗?对于已经实现的功能来说,boost实现通常是合理的。有一些bug,但我们正在处理它们,Vicente正在处理缺失的C++11功能。@AnthonyWilliams感谢boost支持。这是可以信赖的,微软违背了他们的承诺,这让我很难过(不幸的是,当future从promise获得时,使用VS 11-Update 1获得了相同的延迟状态(它与async一起工作)。这个问题早在不久前就向他们报告了,但仍然没有发挥作用。在许多情况下,它实际上违背了使用std::future的目的。至少与boost 1.51一起工作。