Search
 
SCRIPT & CODE EXAMPLE
 

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();
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ save typeid 
Cpp :: c++ console color some digits 
Cpp :: how to set a string equal to another string cpp 
Cpp :: replace character in a string c++ stack overflow 
Cpp :: how to make a sqlite3 object in cpp 
Cpp :: cout hex value 
Cpp :: cpp code for euclids GCD 
Cpp :: initialzing a 2d vector in cpp 
Cpp :: how to output to console c++ 
Cpp :: c++ run loop for 5 seconds 
Cpp :: newline in c++ 
Cpp :: ifstream relative file path 
Cpp :: taking input from user in array in c++ 
Cpp :: c++ absolute value 
Cpp :: cout.flush() in c++ 
Cpp :: c++ round number to whole 
Cpp :: how to make crypto 
Cpp :: float max value c++ 
Cpp :: initialize 2d array c++ memset 
Cpp :: how to get command arguments c++ 
Cpp :: c++ check first character of string 
Cpp :: min vector c++ 
Cpp :: how to check size of file in c++ 
Cpp :: syntax c++ 
Cpp :: array and for loop in c++ 
Cpp :: c++ 20 struct initialization 
Cpp :: how to make a loop in c++ 
Cpp :: cpp binary tree 
Cpp :: c++ find_if 
Cpp :: c++ get ascii value of char 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =