Mercurial > pub > ImplabNet
comparison Implab/Parallels/ArrayTraits.cs @ 19:e3935fdf59a2 promises
Promise is rewritten to use interlocked operations instead of locks
author | cin |
---|---|
date | Sun, 10 Nov 2013 00:21:33 +0400 |
parents | 5a4b735ba669 |
children | ee04e1fa78da |
comparison
equal
deleted
inserted
replaced
17:7cd4a843b4e4 | 19:e3935fdf59a2 |
---|---|
138 var pending = source.Length; | 138 var pending = source.Length; |
139 var semaphore = new Semaphore(threads, threads); | 139 var semaphore = new Semaphore(threads, threads); |
140 | 140 |
141 AsyncPool.InvokeNewThread(() => { | 141 AsyncPool.InvokeNewThread(() => { |
142 for (int i = 0; i < source.Length; i++) { | 142 for (int i = 0; i < source.Length; i++) { |
143 if(promise.State != PromiseState.Unresolved) | 143 if(promise.IsResolved) |
144 break; // stop processing in case of error or cancellation | 144 break; // stop processing in case of error or cancellation |
145 var idx = i; | 145 var idx = i; |
146 semaphore.WaitOne(); | 146 semaphore.WaitOne(); |
147 try { | 147 try { |
148 var p1 = transform(source[i]); | 148 var p1 = transform(source[i]); |