#include <iostream>
#include <future>
#include <chrono>
using namespace std;
using namespace std::chrono;
int sampleFunction(int a)
{
return a;
}
int main()
{
future<int> f1=async(launch::deferred,sampleFunction,10);
future_status statusF1=f1.wait_for(seconds(10));
if(statusF1==future_status::ready)
cout<<"Future is ready"<<endl;
else if (statusF1==future_status::timeout)
cout<<"Timeout occurred"<<endl;
else if (statusF1==future_status::deferred)
cout<<"Task is deferred"<<endl;
cout<<"Value : "<<f1.get()<<endl;
}
Output -
Timeout occurred
Value : 10
在上面的例子中,我期待future_status
to be deferred
代替timeout
. sampleFunction
已推出为launch::deferred
。因此它不会被执行,直到f1.get()
已被调用。在这样的情况下wait_for
应该已经回来了future_status::deferred
并不是future_status::timeout
.
如果有人能帮助我理解这一点,我将不胜感激。
我在 fedora 17 上使用 g++ 版本 4.7.0。
GCC 和 GNU STL 不支持完整的 C++ 11。
在这里您可以查看 GCC 和 GNU STL 中的 C++ 11 实现状态:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
另外,请阅读此讨论主题:http://blog.gmane.org/gmane.comp.gcc.bugs/month=20120201
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)