Use independent resource for each thread in the QThreadPool
-
Assume I am processing a bunch of heavy data(1000 of them) by QtConcurrent::mapped
@auto result = QtConcurrent::mapped(image_id, std::bind<std::pair<QString, QImage>>(&mainWindow::process_image_impl, this, ph::1));
image_sequence.setFuture(result);@instead of
@void process_image_impl(int image_id)
{
//.......lots of codes{
QMutexLocker locker(&mutex);
morphology.close(image, image); //I don't want to lock this operation
}//lots of codes
}@I would like to do something like
@void process_image_impl(int image_id)
{
//.......lots of codesmorphology[thread_id].close(image, image); //I don't want to lock this operation
//lots of codes
}@in the function process_image_impl, I have a class called "morphology", I don't want to lock the class
"morphology" when I process the image, but if I don't lock it I may cause undefined behavior.Instead
of locking the process, I would like to put the class "morphology" in a container and call each
of the "morphology" according to the thread in the QThreadPool, is this possible?Or do you have
other suggestions?Thanksps : it is unrealistic to create 1000 copy of "morphology"