I am new to multithreading so any suggestions would be very appreciated. The following program takes in a vector of integers(eg. 1 2 3 4 5 6 7) and processes each of them as threads. I was wondering if the method with which I join the threads is correct, and if I can make any improvements.
I hope my explanation is clear! Here is my code snippet. Its not the complete code, I'm just ensuring I'm going the right way:
//in main function
//vector's name is 'inputs' and it contains integers
for (int unsigned i = 0; i < inputs.size(); i++) {
thread thread_obj(thread_function, inputs.at(i));
thread_obj.detach();
}
for (int unsigned i = 0; i < inputs.size(); i++) {
thread_obj.join();
}
Aucun commentaire:
Enregistrer un commentaire