Auto reformatted the base, ref #470

This commit is contained in:
emeric
2024-05-24 23:31:52 +02:00
parent 83b868673c
commit 39941d90a3
460 changed files with 8583 additions and 8514 deletions
+16 -16
View File
@@ -19,29 +19,29 @@
#include <functional>
#include <thread>
#include <boost/asio/io_context.hpp>
template <typename It, typename Func>
template<typename It, typename Func>
void parallel_foreach(std::size_t nbWorkers, It begin, It end, Func&& func)
{
if (nbWorkers == 0)
throw std::runtime_error("Invalid worker count");
if (nbWorkers == 0)
throw std::runtime_error("Invalid worker count");
boost::asio::io_context ioContext;
boost::asio::io_context ioContext;
for (It it {begin}; it != end; ++it)
{
auto refValue {std::ref<typename It::value_type>(*it)};
ioContext.post([refValue, &func]() { std::cout << "EXEC FROM WORKER" << std::endl; func(refValue); std::cout << "END EXEC FROM WORKER" << std::endl; });
}
for (It it{ begin }; it != end; ++it)
{
auto refValue{ std::ref<typename It::value_type>(*it) };
ioContext.post([refValue, &func]() { std::cout << "EXEC FROM WORKER" << std::endl; func(refValue); std::cout << "END EXEC FROM WORKER" << std::endl; });
}
std::vector<std::thread> threads;
for (std::size_t i {}; i < nbWorkers - 1; ++i)
threads.emplace_back([&]() { ioContext.run(); });
std::vector<std::thread> threads;
for (std::size_t i{}; i < nbWorkers - 1; ++i)
threads.emplace_back([&]() { ioContext.run(); });
ioContext.run();
ioContext.run();
for (std::thread& t : threads)
t.join();
for (std::thread& t : threads)
t.join();
}