There is a loop which i want to do it in async().
#include<stdio.h>
#include<thread>
#include<iostream>
#include <future>
using namespace std;
void Compute( int i)
{
printf("i=%d\n",i);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
for(int i=0;i<99999;++i)
std::async(std::launch::async, Compute, i);
}
The result is that the loop will finish the job then jump to next iteration. For example, i=0-->(1sec)-->i=1-->(1sec)-->i=2-->.... How to do it continuously without waiting the last iteration?