I'm trying to pass by reference a variable and two vector matrices into a thread. And its not working. Thread copies them as if I passed them normally. I already tried every method I am aware of - lambda, usual reference, std::ref.
void blur(std::vector<std::vector<int>> &matrix, std::vector<std::vector<int>> &temp_matrix, int &blur_radius,
uint32_t top_limit, uint32_t bottom_limit){
blur_radius = 0;
matrix[0][0] = 0;
}
std::vector<std::vector<int>> new_matrix;
std::vector<std::vector<std::vector<int>>> temp_matrix;
temp_matrix.resize(thread_amount);
for (int i = 0; i < thread_amount; ++i) {
thread_vector.emplace_back(std::thread(blur, std::ref(new_matrix), std::ref(temp_matrix[i]),
std::ref(blur_radius), top_limit, bottom_limit));
}
for(auto& t: thread_vector){
t.join();
}
So after function ended its lifetime, and even after all threads are joined, blur_radius doesn't become 0.
I'm doing all of this to create n matrices which correlates to amount of threads. Then each thread does some calculation with its own matrix in function blur() and after all threads join I concatenate all n matrices into 1.
Aucun commentaire:
Enregistrer un commentaire