C++ 11 future_status::deferred not working
c++, c++11, future, multithreading, stl
Solution
GCC and the GNU STL have no support of the complete C++ 11.
Here you can check out the C++ 11 implementation status in GCC and GNU STL:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
Also, read this discussion thread: http://blog.gmane.org/gmane.comp.gcc.bugs/month=20120201
Problem
``` #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 ``` In above example, I was expecting `future_status` to be `deferred` instead of `timeout`. `sampleFunction` has been launched as `launch::deferred`. Hence it will not be executed until `f1.get()` has been called. In such condition `wait_for` should have returned `future_status::deferred` and not `future_status::timeout`. Appreciate if someone can help me understand this. I am using g++ version 4.7.0 on fedora 17.