@@ -244,7 +244,7 namespace Implab.Test { | |||||
244 | [TestMethod] |
|
244 | [TestMethod] | |
245 | public void ChainedMapTest() { |
|
245 | public void ChainedMapTest() { | |
246 |
|
246 | |||
247 | using (var pool = new WorkerPool(0,100,0)) { |
|
247 | using (var pool = new WorkerPool(0,100,100)) { | |
248 | int count = 10000; |
|
248 | int count = 10000; | |
249 |
|
249 | |||
250 | double[] args = new double[count]; |
|
250 | double[] args = new double[count]; |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -155,7 +155,7 namespace Implab.Parallels { | |||||
155 | } |
|
155 | } | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 |
pr |
|
158 | protected void EnsurePoolIsAlive() { | |
159 | if (AllocateThreadSlot(1)) { |
|
159 | if (AllocateThreadSlot(1)) { | |
160 | // if there were no threads in the pool |
|
160 | // if there were no threads in the pool | |
161 | var worker = new Thread(this.Worker); |
|
161 | var worker = new Thread(this.Worker); | |
@@ -164,7 +164,7 namespace Implab.Parallels { | |||||
164 | } |
|
164 | } | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 |
pr |
|
167 | protected virtual bool Suspend() { | |
168 | //no tasks left, exit if the thread is no longer needed |
|
168 | //no tasks left, exit if the thread is no longer needed | |
169 | bool last; |
|
169 | bool last; | |
170 | bool requestExit; |
|
170 | bool requestExit; | |
@@ -295,7 +295,6 namespace Implab.Parallels { | |||||
295 | InvokeUnit(unit); |
|
295 | InvokeUnit(unit); | |
296 | continue; |
|
296 | continue; | |
297 | } |
|
297 | } | |
298 |
|
||||
299 | Interlocked.Decrement(ref m_activeThreads); |
|
298 | Interlocked.Decrement(ref m_activeThreads); | |
300 |
|
299 | |||
301 | // entering suspend state |
|
300 | // entering suspend state |
@@ -69,6 +69,22 namespace Implab.Parallels { | |||||
69 | return false; |
|
69 | return false; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
|
72 | protected override bool Suspend() { | |||
|
73 | // This override solves race condition | |||
|
74 | // WORKER CLIENT | |||
|
75 | // --------------------------------------- | |||
|
76 | // TryDeque == false | |||
|
77 | // Enqueue(unit), queueLen++ | |||
|
78 | // GrowPool? == NO | |||
|
79 | // ActiveThreads-- | |||
|
80 | // Suspend | |||
|
81 | // queueLength > 0 | |||
|
82 | // continue | |||
|
83 | if (m_queueLength > 0) | |||
|
84 | return true; | |||
|
85 | return base.Suspend(); | |||
|
86 | } | |||
|
87 | ||||
72 | protected override void InvokeUnit(Action unit) { |
|
88 | protected override void InvokeUnit(Action unit) { | |
73 | unit(); |
|
89 | unit(); | |
74 | } |
|
90 | } |
General Comments 0
You need to be logged in to leave comments.
Login now