mardi 28 août 2018

Parallelism with std::async launch not happening , same thread is executing

I am trying to exploit the std::async functionality to do parallelism. But if i print the thread id, it's always returning the same value. Semms like it's running this code sequentially. Am i missing something?

Code :

int main()
{
    bool check = false;
    auto func = [&](int i) 
                          { 
                            std::cout<<"  i : "<<i<<"  thread_id : "<<std::this_thread::get_id()<<" ";
                            check = true;
                          }

    for(int j=0;j<10;j++)
    {
        std::async(std::async::launch, func, j);
    }

    std::cout<<" check : "<<check<<" ";

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire