public void CalculateNumbers(UInt64 start, UInt64 end, UInt64 threadNo) { new Thread(() => { Console.WriteLine("Working [{0}, {1}]", start, end); // Sum { UInt64 total = 0; for (UInt64 i = start; i < end; ++i) { total += (UInt64)nums[i]; } resultStore[threadNo] = total; Console.WriteLine("Thread sum:\t {0}", total); if (syncBarrier.Arrive()) { UInt64 agregateTotal = 0; for (UInt64 i = 0; i < workers; ++i) { agregateTotal += resultStore[i]; } Console.WriteLine("Aggregate:\t {0}", agregateTotal); Console.WriteLine("Average:\t {0}", agregateTotal / (UInt64)workers); Console.WriteLine("--------------------------------------"); calculationsCompleted.Release(workers); } calculationsCompleted.Acquire(); } // Min { UInt64 min = nums[0]; for (UInt64 i = start; i < end; ++i) { if (nums[i] < min) { min = nums[i]; } } resultStore[threadNo] = min; Console.WriteLine("Thread min:\t {0}", min); if (syncBarrier.Arrive()) { UInt64 smallest = resultStore[0]; for (UInt64 i = 0; i < workers; ++i) { if (resultStore[i] < smallest) { smallest = resultStore[i]; } } Console.WriteLine("Smallest:\t {0}", smallest); Console.WriteLine("--------------------------------------"); calculationsCompleted.Release(workers); } calculationsCompleted.Acquire(); } // Max { UInt64 max = nums[0]; for (UInt64 i = start; i < end; ++i) { if (nums[i] > max) { max = nums[i]; } } resultStore[threadNo] = max; Console.WriteLine("Thread max:\t {0}", max); if (syncBarrier.Arrive()) { UInt64 largest = resultStore[0]; for (UInt64 i = 0; i < workers; ++i) { if (resultStore[i] > largest) { largest = resultStore[i]; } } Console.WriteLine("Largest:\t {0}", largest); Console.WriteLine("--------------------------------------"); calculationsCompleted.Release(workers); } calculationsCompleted.Acquire(); } }).Start(); }