public void ShouldWaitForAllActionsToFinishBeforeReturning( [Column(0, 1, 2, 7, 19)] int numActions) { Stopwatch stopwatch = Stopwatch.StartNew(); bool[] finished = new bool[numActions]; GallioAction[] actions = new GallioAction[numActions]; for (int i = 0; i < numActions; i++) { int actionIndex = i; actions[i] = () => { Thread.Sleep((actionIndex + 1) * 71 % 37); TestLog.WriteLine("Iteration #{0} finished after {1}ms", actionIndex + 1, stopwatch.ElapsedMilliseconds); finished[actionIndex] = true; }; } var scheduler = new WorkScheduler(() => maxThreads); scheduler.Run(actions); for (int i = 0; i < numActions; i++) { Assert.IsTrue(finished[i]); } }
private static int Fibonnaci(WorkScheduler scheduler, int count) { if (count < 2) { return(count); } int sum = 0; scheduler.Run(new GallioAction[] { () => Interlocked.Add(ref sum, Fibonnaci(scheduler, count - 1)), () => Interlocked.Add(ref sum, Fibonnaci(scheduler, count - 2)) }); return(sum); }