diff Implab/Parallels/WorkerPool.cs @ 81:2c5631b43c7d v2

dispatch pool rewritten
author cin
date Fri, 26 Sep 2014 20:44:01 +0400
parents 4f20870d0816
children 4c0e5ef99986
line wrap: on
line diff
--- a/Implab/Parallels/WorkerPool.cs	Fri Sep 26 03:32:34 2014 +0400
+++ b/Implab/Parallels/WorkerPool.cs	Fri Sep 26 20:44:01 2014 +0400
@@ -66,10 +66,11 @@
             var len = Interlocked.Increment(ref m_queueLength);
             m_queue.Enqueue(unit);
 
-            if (len > m_threshold * m_workers) {
-                Interlocked.Increment(ref m_workers);
-                GrowPool();
+            if (len > m_threshold * PoolSize) {
+                StartWorker();
             }
+
+            SignalThread();
         }
 
         protected override bool TryDequeue(out Action unit) {
@@ -80,24 +81,6 @@
             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
-            Thread.MemoryBarrier();
-            if (m_queueLength > 0)
-                return true;
-            Interlocked.Decrement(ref m_workers);
-            return base.Suspend();
-        }
-
         protected override void InvokeUnit(Action unit) {
             unit();
         }