dimanche 29 mars 2015

Launching Multiple Threads in a single call C++ 11

The typical way to create multiple threads in C++ 11 as I understand is:



int num_threads = 10;
std::thread threads[num_threads];
for(int i = 0; i < num_threads; ++i)
{
threads[i] = std::thread(doSomething);
}
// Call join if you need all threads completion
for(int i = 0; i < num_threads; ++i)
{
threads[i].join();
}


Is it possible to launch the threads in one shot, instead of using a loop to start each thread sequentially. I know in CUDA, threads are launched simultaneously and there is no need to start each one individually. Wondering if something similar is possible in C++ 11.


Aucun commentaire:

Enregistrer un commentaire