diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 4be46aee6..fc9fda850 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1094,6 +1094,13 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink { } + ~GitFileSystemObjectSinkImpl() + { + // Make sure the worker threads are destroyed before any state + // they're referring to. + workers.shutdown(); + } + struct Child; /// A directory to be written as a Git tree. diff --git a/src/libutil/include/nix/util/thread-pool.hh b/src/libutil/include/nix/util/thread-pool.hh index a07354146..61fea39b7 100644 --- a/src/libutil/include/nix/util/thread-pool.hh +++ b/src/libutil/include/nix/util/thread-pool.hh @@ -52,6 +52,12 @@ public: */ void process(); + /** + * Shut down all worker threads and wait until they've exited. + * Active work items are finished, but any pending work items are discarded. + */ + void shutdown(); + private: size_t maxThreads; @@ -72,8 +78,6 @@ private: std::condition_variable work; void doWork(bool mainThread); - - void shutdown(); }; /**