Created
April 27, 2017 13:50
-
-
Save KPB3rd/d3c0299c452281453561c2e513c84169 to your computer and use it in GitHub Desktop.
Simple Parallel For Loop C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialize detector vector | |
| if (targetDetectors.size() == 0) | |
| { | |
| for (unsigned iter = 0; iter < inputImages.size(); iter++) targetDetectors.push_back(CalibTargetDetector()); | |
| } | |
| // Create Output vector | |
| for (unsigned iter = 0; iter < inputImages.size(); iter++) targetImages.push_back(TypedObject<cv::Mat>(cv::Mat())); | |
| std::vector<std::thread*> threads(inputImages.size()); | |
| for (int t = 0; t < threads.size(); t++) | |
| { | |
| threads[t] = new std::thread(&DetectTargetImpl::DetectTargetThreaded, this, t); | |
| } | |
| // Wait for threads to finish | |
| std::for_each(threads.begin(), threads.end(), [](std::thread* x){ x->join(); }); | |
| // Free threads | |
| for (unsigned iter = 0; iter < threads.size(); iter++) delete threads[iter]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment