[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "alternate_thread_cleanup" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Jun 27 14:00:44 CDT 2012


branch "alternate_thread_cleanup" has been created
        at  dd106821624a7b45b6011c8e8ffa37d137c83892 (commit)

- Log -----------------------------------------------------------------
commit dd106821624a7b45b6011c8e8ffa37d137c83892
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Jun 27 16:27:46 2012 -0230

    Move thread cleanup out of the WorkerThread destructor and have the thread pool mark the worker thread as dead explicitly from the killThreads method.

diff --git a/src/ThreadPool/ThreadPool.cpp b/src/ThreadPool/ThreadPool.cpp
index 44ce0df..005bd27 100644
--- a/src/ThreadPool/ThreadPool.cpp
+++ b/src/ThreadPool/ThreadPool.cpp
@@ -101,6 +101,14 @@ public:
     void killThreads(ThreadContainer& container,
             ThreadIterator first, ThreadIterator last)
     {
+        for(ThreadIterator iter = first; iter != last; ++iter)
+        {
+            //
+            // It is important to tell the worker thread that it is done
+            // here so we can avoid unnecessary mishaps!
+            //
+            (*iter)->setState(Dead);
+        }
         container.erase(first, last);
     }
 
diff --git a/src/ThreadPool/WorkerThread.cpp b/src/ThreadPool/WorkerThread.cpp
index d8a68b8..8890785 100644
--- a/src/ThreadPool/WorkerThread.cpp
+++ b/src/ThreadPool/WorkerThread.cpp
@@ -101,16 +101,23 @@ WorkerThread::WorkerThread(const QueuePtr& workQueue, WorkerThreadListener *list
 
 WorkerThread::~WorkerThread()
 {
-    setState(Dead);
-    mPriv->mThread.join();
+    //
+    // We can't do stuff with the worker thread here!
+    //
 }
 
 void WorkerThread::setState(ThreadState newState)
 {
-    boost::unique_lock<boost::mutex> lock(mPriv->mLock);
-    mPriv->mState = newState;
-    mPriv->mWakeUp = true;
-    mPriv->mCond.notify_one();
+    {
+        boost::lock_guard<boost::mutex> lock(mPriv->mLock);
+        mPriv->mState = newState;
+        mPriv->mWakeUp = true;
+        mPriv->mCond.notify_one();
+    }
+    if (newState == Dead)
+    {
+        mPriv->mThread.join();
+    }
 }
 
 bool WorkerThread::operator==(const WorkerThread& rhs)

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list