@@ -163,16 +163,18 namespace Implab.Parallels { | |||
|
163 | 163 | break; // stop processing in case of error or cancellation |
|
164 | 164 | var idx = i; |
|
165 | 165 | |
|
166 | if (Interlocked.Decrement(ref slots) < 0) { | |
|
166 | 167 | lock(locker) { |
|
167 |
while(slots |
|
|
168 | while(slots < 0) | |
|
168 | 169 | Monitor.Wait(locker); |
|
169 |
|
|
|
170 | } | |
|
170 | 171 | } |
|
172 | ||
|
171 | 173 | try { |
|
172 | 174 | transform(source[i]) |
|
173 | 175 | .Anyway(() => { |
|
176 | Interlocked.Increment(ref slots); | |
|
174 | 177 | lock(locker) { |
|
175 | slots ++; | |
|
176 | 178 | Monitor.Pulse(locker); |
|
177 | 179 | } |
|
178 | 180 | }) |
@@ -183,7 +185,7 namespace Implab.Parallels { | |||
|
183 | 185 | if (left == 0) |
|
184 | 186 | promise.Resolve(res); |
|
185 | 187 | }, |
|
186 |
|
|
|
188 | promise.Reject | |
|
187 | 189 | ); |
|
188 | 190 | |
|
189 | 191 | } catch (Exception e) { |
@@ -69,7 +69,7 namespace Implab.Parallels { | |||
|
69 | 69 | |
|
70 | 70 | protected abstract bool TryDequeue(out TUnit unit); |
|
71 | 71 | |
|
72 |
|
|
|
72 | bool Dequeue(out TUnit unit, int timeout) { | |
|
73 | 73 | int ts = Environment.TickCount; |
|
74 | 74 | if (TryDequeue(out unit)) |
|
75 | 75 | return true; |
General Comments 0
You need to be logged in to leave comments.
Login now