/
BirdLeon
/
ROBLOX2016
Обзор
Документация
Войти
/
BirdLeon
/
ROBLOX2016
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Base.UnitTest/concurrent.h
43 строки
1 KB
PatoFlamejanteTV
full source code
19 дек 2024, 19:11
19 дек 2024, 19:11
05db15d
Код
Авторство
О чём код?
#pragma once #include <boost/thread.hpp> namespace util { template <typename F> struct ConcurrentLoops { static int run(F f, int iterations, int num_threads) { int result = 0; std::vector<std::pair<boost::thread*, int> > 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