diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index e7e030a55..aca310fec 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -306,9 +306,7 @@ void Store::addMultipleToStore( act.progress(nrDone, pathsToCopy.size(), nrRunning, nrFailed); }; - ThreadPool pool{"addMultipleToStore pool"}; - - processGraph(pool, + processGraph("addMultipleToStore pool", storePathsToAdd, [&](const StorePath & path) { @@ -1137,12 +1135,10 @@ std::map copyPaths( } auto pathsMap = copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute); - ThreadPool pool{"copyPaths pool"}; - try { // Copy the realisation closure processGraph( - pool, Realisation::closure(srcStore, toplevelRealisations), + "copyPaths pool", Realisation::closure(srcStore, toplevelRealisations), [&](const Realisation & current) -> std::set { std::set children; for (const auto & [drvOutput, _] : current.dependentRealisations) { diff --git a/lix/libutil/thread-pool.hh b/lix/libutil/thread-pool.hh index 089fdd3f3..9db56805a 100644 --- a/lix/libutil/thread-pool.hh +++ b/lix/libutil/thread-pool.hh @@ -85,7 +85,7 @@ private: */ template void processGraph( - ThreadPool & pool, + const char *poolName, const std::set & nodes, std::function(const T &)> getEdges, std::function processNode) @@ -99,6 +99,11 @@ void processGraph( std::function worker; + /* Create pool last to ensure threads are stopped before other destructors + * run */ + ThreadPool pool{poolName}; + + worker = [&](const T & node) { {