Category : std-future

I expect the below code to all work everytime. Currently std::future.get() blocks in both branches everytime. It blocks forever despite wait_for() showing the status as ready and wait() returning immediately. Same result for gcc 7.4.0 & clang 6.0.0. #include <chrono> #include <condition_variable> #include <future> #include <functional> #include <iostream> #include <mutex> #include <queue> #include <cassert> #include ..

Read more

Edit: my question is different from the suggested question becaude I cannot poll 100’s of future.get() and wait to execute the remaining program in main() thread. I am hoping the threads to return the value when the thread is done executing and then the calling function should run. As per this question in C++ future ..

Read more

I have the main thread, which calls a function using std:async. void fileIO() { while (true) { SomeClass::someStaticFunction(); } } int main() { … … std::future<void> fileIOFuture = async(std::launch::async, fileIO); while (!exitMainloop) // this value is set somewhere else in the code: https://github.com/TigerVNC/tigervnc/blob/master/vncviewer/vncviewer.cxx#L702 run_mainloop(); delete cc; // cc is some class return 0; } What ..

Read more

I know that std::async is a C++11 thing but I am pretty sure that my compiler has C++11 support. #include <future> using namespace::std; void functionToRun() { // some code } int main() { auto x = 2; // throws warning warning: ‘auto’ type specifier is a C++11 extension [-Wc++11-extensions] std::future<void> metricLoggerFuture = std::async(std::launch::async, functionToRun); // ..

Read more

I am using std::async and std::future for the first time and am getting the error, Can somone help me rectify it. The error : ** terminate called after throwing an instance of ‘std::future_error’ what(): std::future_error: No associated state** The code : ”’ long long best_move(int depth, int start_score, char state[8][9], int state_score[8][8], long long alpha, ..

Read more