[Libreoffice-commits] core.git: comphelper/source

Michael Stahl mstahl at redhat.com
Wed Mar 22 10:44:39 UTC 2017


 comphelper/source/misc/threadpool.cxx |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

New commits:
commit 64c09371d6feed6e87aaa54cde081f001dcfca10
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Mar 22 10:47:06 2017 +0100

    comphelper::ThreadPool: guard against concurrent shutdown/pushTask
    
    To join a thread, the mutex must be released - another thread
    in pushTask() could add a new thread to maWorkers at that point,
    which must of course not be deleted.
    
    Avoid the problem by transferring ownership of the to-be-deleted
    threads to the calling thread.
    
    (regression from bdaa13a87744e424d3c210fc7f3f9e4f199d8279)
    
    Change-Id: I9d4fcfe4cb46a336586b5663934a12d47b2d8ccb

diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx
index 3aaf344c3ba8..2c8a116c4e56 100644
--- a/comphelper/source/misc/threadpool.cxx
+++ b/comphelper/source/misc/threadpool.cxx
@@ -157,18 +157,20 @@ void ThreadPool::shutdownLocked(std::unique_lock<std::mutex>& aGuard)
 
     maTasksChanged.notify_all();
 
-    while( !maWorkers.empty() )
+    decltype(maWorkers) aWorkers;
+    std::swap(maWorkers, aWorkers);
+    aGuard.unlock();
+
+    while (!aWorkers.empty())
     {
-        rtl::Reference< ThreadWorker > xWorker = maWorkers.back();
-        maWorkers.pop_back();
-        assert(std::find(maWorkers.begin(), maWorkers.end(), xWorker)
-                == maWorkers.end());
-        aGuard.unlock();
+        rtl::Reference<ThreadWorker> xWorker = aWorkers.back();
+        aWorkers.pop_back();
+        assert(std::find(aWorkers.begin(), aWorkers.end(), xWorker)
+                == aWorkers.end());
         {
             xWorker->join();
             xWorker.clear();
         }
-        aGuard.lock();
     }
 }
 


More information about the Libreoffice-commits mailing list