diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-03-21 15:18:01 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-03-21 16:15:36 +0000 |
commit | bdaa13a87744e424d3c210fc7f3f9e4f199d8279 (patch) | |
tree | 3eebebe404ea656cb87dd04ddeea32b926e47827 /include/comphelper | |
parent | 9f3b59a511b15328284f4f25b7ac0cd89ba1a303 (diff) |
comphelper:: fix MSVC hang in ThreadPool::shutdown(), try #2
This takes a different approach than commit
9899ffd244dd367ba69dffe1f21f4f0222064a46.
Change the ThreadPool to automatically shutdown and join all threads
whenever waitUntilDone() is called. Then start the threads again
in pushTask().
Because the ThreadPool is meant to be used synchronously with
waitUntilDone() called after adding all required tasks, this should
obviate the need to call shutdown() before process exit, as
there won't be any threads running at that point.
Change-Id: I2b8e639004a94cf05ccb4522aa1f0d3dac88a936
Reviewed-on: https://gerrit.libreoffice.org/35510
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'include/comphelper')
-rw-r--r-- | include/comphelper/threadpool.hxx | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx index 32fcb64198d7..66ade62f3f8f 100644 --- a/include/comphelper/threadpool.hxx +++ b/include/comphelper/threadpool.hxx @@ -68,7 +68,7 @@ public: void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&); /// return the number of live worker threads - sal_Int32 getWorkerCount() const { return maWorkers.size(); } + sal_Int32 getWorkerCount() const { return mnWorkers; } /// wait until all work is completed, then join all threads void shutdown(); @@ -85,11 +85,13 @@ private: @return a new task to perform, or NULL if list empty or terminated */ ThreadTask *popWorkLocked( std::unique_lock< std::mutex > & rGuard, bool bWait ); + void shutdownLocked(std::unique_lock<std::mutex>&); /// signalled when all in-progress tasks are complete std::mutex maMutex; std::condition_variable maTasksChanged; bool mbTerminate; + std::size_t mnWorkers; std::vector< ThreadTask * > maTasks; std::vector< rtl::Reference< ThreadWorker > > maWorkers; }; |