c++ – Which of these Boost Asio multithread tcp server examples is more correct?
Have seen two different examples of this and what/which one is correct?
-
std::vector<std::thread> threads; -
boost::asio::io_context io_context{(int)threads};
std::vector<std::thread> threads;
auto count = std::thread::hardware_concurrency();
for (unsigned int n = 0; n < count; ++n) {
threads.emplace_back([&] { io_context->run(); });
}
for (auto &thread : threads) {
if (thread.joinable())
thread.join();
}
auto threads = std::thread::hardware_concurrency();
boost::asio::io_context io_context{(int)threads};
std::vector<std::thread> v;
v.reserve(threads - 1);
for(auto i = threads - 1; i > 0; --i)
v.emplace_back(
[&io_context]
{
io_context.run();
});
io_context.run();
Read more here: Source link
