##// END OF EJS Templates
implemented parallel map and foreach for arrays...
implemented parallel map and foreach for arrays rewritten WorkerPool with MTQueue for more efficiency

File last commit:

r15:0f982f9b7d4d promises
r15:0f982f9b7d4d promises
Show More
WorkerPool.cs
69 lines | 1.9 KiB | text/x-csharp | CSharpLexer
cin
refactoring, added WorkerPool
r12 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace Implab.Parallels {
cin
implemented parallel map and foreach for arrays...
r15 public class WorkerPool : DispatchPool<Action> {
cin
refactoring, added WorkerPool
r12
cin
implemented parallel map and foreach for arrays...
r15 MTQueue<Action> m_queue = new MTQueue<Action>();
int m_queueLength = 0;
cin
small fixes, WorkerPool still incomplete
r13
cin
implemented parallel map and foreach for arrays...
r15 public WorkerPool(int minThreads, int maxThreads)
: base(minThreads, maxThreads) {
InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
implemented parallel map and foreach for arrays...
r15 public WorkerPool(int threads)
: base(threads) {
InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
implemented parallel map and foreach for arrays...
r15 public WorkerPool()
: base() {
InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
refactoring, added WorkerPool
r12 public Promise<T> Invoke<T>(Func<T> task) {
if (task == null)
throw new ArgumentNullException("task");
cin
implemented parallel map and foreach for arrays...
r15 if (IsDisposed)
throw new ObjectDisposedException(ToString());
cin
refactoring, added WorkerPool
r12
var promise = new Promise<T>();
cin
implemented parallel map and foreach for arrays...
r15 EnqueueTask(delegate() {
cin
small fixes, WorkerPool still incomplete
r13 try {
promise.Resolve(task());
} catch (Exception e) {
promise.Reject(e);
}
});
cin
refactoring, added WorkerPool
r12
return promise;
}
cin
implemented parallel map and foreach for arrays...
r15 protected void EnqueueTask(Action unit) {
Debug.Assert(unit != null);
Interlocked.Increment(ref m_queueLength);
m_queue.Enqueue(unit);
// if there are sleeping threads in the pool wake one
// probably this will lead a dry run
WakeNewWorker();
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 protected override bool TryDequeue(out Action unit) {
if (m_queue.TryDequeue(out unit)) {
Interlocked.Decrement(ref m_queueLength);
return true;
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 return false;
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 protected override void InvokeUnit(Action unit) {
unit();
cin
refactoring, added WorkerPool
r12 }
}
}