From 4f4cf16be11d2820974c1d6a0e95c9af3281e2d1 Mon Sep 17 00:00:00 2001 From: Adam Midvidy Date: Mon, 23 Nov 2015 17:58:08 -0500 Subject: SERVER-21640 fix race in getting size of _serviceRunners in NetworkInterfaceASIO --- src/mongo/executor/network_interface_asio.cpp | 32 +++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/mongo/executor/network_interface_asio.cpp') diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp index 776b372e9bd..b609c368269 100644 --- a/src/mongo/executor/network_interface_asio.cpp +++ b/src/mongo/executor/network_interface_asio.cpp @@ -105,23 +105,21 @@ std::string NetworkInterfaceASIO::getHostName() { } void NetworkInterfaceASIO::startup() { - std::generate_n(std::back_inserter(_serviceRunners), - kIOServiceWorkers, - [&] { - return stdx::thread([this]() { - setThreadName(_options.instanceName + "-" + - std::to_string(_serviceRunners.size())); - try { - LOG(2) << "The NetworkInterfaceASIO worker thread is spinning up"; - asio::io_service::work work(_io_service); - _io_service.run(); - } catch (...) { - severe() << "Uncaught exception in NetworkInterfaceASIO IO " - "worker thread of type: " << exceptionToStatus(); - fassertFailed(28820); - } - }); - }); + _serviceRunners.resize(kIOServiceWorkers); + for (std::size_t i = 0; i < kIOServiceWorkers; ++i) { + _serviceRunners[i] = stdx::thread([this, i]() { + setThreadName(_options.instanceName + "-" + std::to_string(i)); + try { + LOG(2) << "The NetworkInterfaceASIO worker thread is spinning up"; + asio::io_service::work work(_io_service); + _io_service.run(); + } catch (...) { + severe() << "Uncaught exception in NetworkInterfaceASIO IO " + "worker thread of type: " << exceptionToStatus(); + fassertFailed(28820); + } + }); + }; _state.store(State::kRunning); } -- cgit v1.2.1