#pragma once #include namespace util { template struct ConcurrentLoops { static int run(F f, int iterations, int num_threads) { int result = 0; std::vector > threads(num_threads); int index = 0; for (auto &it : threads) { it.first = new boost::thread(threadFunc, f, index++, iterations, it.second); } for (auto &it : threads) { it.first->join(); delete it.first; it.first = 0; if (it.second) result = it.second; } return result; } private: static void threadFunc(F &f, int index, int iterations, int &result) { for (int i = 0; i < iterations; ++i) { result = f(index); if (result) break; } } }; // struct ConcurrentLoops } // namespace utils