1

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?

  • 1
    Using the `std` prefix is good, a lot better than using the `using namespace std`, using both, is not really of any benefit. :) – Tommy Andersen May 22 '18 at 15:51

0 Answers0