diff Implab/Parallels/WorkerPool.cs @ 34:dabf79fde388

fixed race condition in DispatchPool
author cin
date Thu, 10 Apr 2014 04:20:25 +0400
parents 6a56df4ec59e
children 2880242f987a
line wrap: on
line diff
--- a/Implab/Parallels/WorkerPool.cs	Thu Apr 10 02:39:29 2014 +0400
+++ b/Implab/Parallels/WorkerPool.cs	Thu Apr 10 04:20:25 2014 +0400
@@ -69,6 +69,22 @@
             return false;
         }
 
+        protected override bool Suspend() {
+            // This override solves race condition
+            // WORKER                   CLIENT
+            // ---------------------------------------
+            // TryDeque == false
+            //                          Enqueue(unit), queueLen++
+            //                          GrowPool? == NO
+            // ActiveThreads--
+            // Suspend
+            //    queueLength > 0
+            // continue
+            if (m_queueLength > 0)
+                return true;
+            return base.Suspend();
+        }
+
         protected override void InvokeUnit(Action unit) {
             unit();
         }