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