Exemple #1
0
        public int getPop()
        {
            int alive = 0;

            Task[] tasks = new Task[numThreads];
            for (int i = 0; i < numThreads; i++)
            {
                var i2       = i;
                int minRange = worldlength / numThreads * i;
                int maxRange = worldlength / numThreads * (i + 1);
                tasks[i] = (Task.Factory.StartNew(() => Threads.popCount(minRange, maxRange, ref alive)));
            }
            Task.WaitAll(tasks);
            return(alive);
        }
Exemple #2
0
 public void threadedAdvance()
 {
     newworld = (bool[, ])world.Clone();
     Task[] tasks = new Task[numThreads];
     for (int i = 0; i < numThreads; i++)
     {
         var i2       = i;
         int minRange = worldlength / numThreads * i;
         int maxRange = worldlength / numThreads * (i + 1);
         tasks[i] = (Task.Factory.StartNew(() => Threads.advance(min: minRange, max: maxRange, name: i2.ToString())));
     }
     Task.WaitAll(tasks);
     //All threads have run, time to update the world
     world = (bool[, ])newworld.Clone();
 }