I have an array containing vectors
std::vector<int> A[10];
I want to copy all the values from all the vectors from array A to another vector of integers B using multithreading
std::vector<int> B;
In order to do that in multithreading, I have an array containing positions where each vector from array A will be in the vector B. And to copy, I am using lambda expression:
int positions[10];
for (int i = 0; i < 10; i++)
{
std::async( std::launch::async, [](std::vector<uint32_t>::iterator first, std::vector<uint32_t>::iterator last, std::vector<uint32_t>::iterator d_first) {std::copy(first, last, d_first);}, (*A[i]).begin(), (*A[i]).end(), B.begin() + positions[i]));
}
Now this is working fine. It creates 10 threads and each thread copies vector from array A to B with defined positions. But the problem is, it needs copy all the values using limited threads. For example 2.
Then instead of passing one vector for copy in lambda function I need to pass 5 vectors(then of course position array will have only two position values) for each thread.
Is there any way I can modify the lambda function to do that? Or any other possible solution?
Thank you in advance :)