diff Implab/Parallels/DispatchPool.cs @ 24:ee04e1fa78da

fixed dispatch pool race condition
author cin
date Thu, 14 Nov 2013 01:15:07 +0400
parents 5a35900264f5
children 2fad2d1f4b03
line wrap: on
line diff
--- a/Implab/Parallels/DispatchPool.cs	Wed Nov 13 14:03:20 2013 +0400
+++ b/Implab/Parallels/DispatchPool.cs	Thu Nov 14 01:15:07 2013 +0400
@@ -151,7 +151,10 @@
                 }
             } else {
                 // if there is no sleeping threads in the pool
-                StartWorker();
+                if (!StartWorker())
+                    // we haven't started a new thread, but the current can be on the way and it can't process the queue
+                    // send it a signal to spin again
+                    SignalThread(); 
             }
         }
 
@@ -281,7 +284,6 @@
                         m_hasTasks.Dispose();
                     else
                         SignalThread(); // wake next worker
-                    unit = default(TUnit);
                     break;
                 }