-
-
Save sdi1982/ba7b8532c8477fd79057848af10a3143 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