Quantcast
Channel: Installation and Deployment
Viewing all articles
Browse latest Browse all 22112

Use independent resource for each thread in the QThreadPool

$
0
0
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 codes         morphology[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?Thanks ps : it is unrealistic to create 1000 copy of “morphology”

Viewing all articles
Browse latest Browse all 22112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>