public static void For(SBThreadPool pool, int inclusiveStart, int exclusiveEnd, ParallelForIterationDelegate iterate) { if(inclusiveStart >= exclusiveEnd) return; using (ParallelForRun loopRun = new ParallelForRun(exclusiveEnd - inclusiveStart, inclusiveStart, iterate)) { for (int i = 0; i < pool.NumThreads; i++) { SBJob job = new ParallelForJob(loopRun); job.QueueInPool(pool); } loopRun.ThreadRunIterations(); loopRun.Join(); } }
public abstract void Run(SBThreadPool pool);
#pragma warning restore 0420 public void QueueInPool(SBThreadPool pool) { finishedVar = 0; pool.AddWork(RunAndMarkDone); }
#pragma warning disable 0420 // a reference to a volatile field will not be treated as volatile private void RunAndMarkDone(SBThreadPool pool) { Run(pool); Interlocked.Increment(ref finishedVar); }
public sealed override void Run(SBThreadPool pool) { loopRun.ThreadRunIterations(); }