diff --git a/src/qbdt/tree.cpp b/src/qbdt/tree.cpp index b649fdc65..c57fea63b 100644 --- a/src/qbdt/tree.cpp +++ b/src/qbdt/tree.cpp @@ -93,9 +93,10 @@ void QBdt::par_for_qbdt(const bitCapInt& end, bitLenInt maxQubit, BdtFunc fn) std::mutex myMutex; bitCapInt idx = 0U; - std::vector> futures(threads); + std::vector> futures; + futures.reserve(threads); for (unsigned cpu = 0U; cpu != threads; ++cpu) { - futures[cpu] = std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, fn]() { + futures.push_back(std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, fn]() { for (;;) { bitCapInt i; if (true) { @@ -119,10 +120,10 @@ void QBdt::par_for_qbdt(const bitCapInt& end, bitLenInt maxQubit, BdtFunc fn) } } } - }); + })); } - for (unsigned cpu = 0U; cpu != threads; ++cpu) { + for (unsigned cpu = 0U; cpu < futures.size(); ++cpu) { futures[cpu].get(); } #else @@ -152,9 +153,10 @@ void QBdt::_par_for(const bitCapInt& end, ParallelFuncBdt fn) std::mutex myMutex; bitCapInt idx = 0U; - std::vector> futures(threads); + std::vector> futures; + futures.reserve(threads); for (unsigned cpu = 0U; cpu != threads; ++cpu) { - futures[cpu] = std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, cpu, fn]() { + futures.push_back(std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, cpu, fn]() { for (;;) { bitCapInt i; if (true) { @@ -170,10 +172,10 @@ void QBdt::_par_for(const bitCapInt& end, ParallelFuncBdt fn) fn(j + l, cpu); } } - }); + })); } - for (unsigned cpu = 0U; cpu != threads; ++cpu) { + for (unsigned cpu = 0U; cpu < futures.size(); ++cpu) { futures[cpu].get(); } #else