1

I have a code that does image processing on 4 images and then gives some result. At present the code is single threaded and very slow. Since each image can be processed individually, is it necessary to have mutex locking ?

Here is a pseudo code:

std::vector<Image> images(4);
// load images in the above container ...
// launch threads for each individual image
std::vector<std::thread> threads;
for(int i = 0; i < 4; ++i) {
    threads.emplace_back(worker_function, std::ref(images[i]));
}

and the worker function will be something like:

void worker_function(Image& img) {
    // do some stuff with the image
    ...
    // save the modified image in the same location
    img = img;
}

Since each thread will be working on the individual Image element do I need to put in mutex locks?

Manmohan Bishnoi
  • 791
  • 13
  • 37

0 Answers0