Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ std::async wait is taking forever

//it is perfectly normal that std::future::wait takes a long time,
//std::future::wait will wait until the corresponding async is finished

std::vector<std::future<void>> future_vals;
future_val.reserve(450);
for(size_t i = 0; i < 450; i++){ //we start 450 task, this is relatively fast
  future_val.push_back(std::async(std::launch::async, foo, i));
}

//we can do something else while the async tasks are runnings
Bar();

//we wait for all the task to be finished before we keep going,
//it's slow and in this case the execution time
//is about (450 * execTimeOfFoo / numberOfLogicalProcessors) - execTimeOfBar
for(auto& i : future_val){
  i.wait();
}
 
PREVIOUS NEXT
Tagged: #wait
ADD COMMENT
Topic
Name
5+6 =