#include "../include/ThreadPool_pthread.h" #include #include void* SumZeroToNumber(void* num) { long val = 0; for(long i = 0; i <= *static_cast(num); i++) { val += i; } *static_cast(num) = val; return NULL; } int main() { std::vector nums(10000); std::vector numsResults(10000); try { ThreadPool_pthread pool(8); //num of cores for(unsigned i = 0; i < nums.size(); i++) { nums[i] = rand() % 1000; numsResults[i] = nums[i]; //this is just a copy to be passed and modified, while the original remains unchanged pool.push_task(SumZeroToNumber,static_cast(&numsResults[i])); } pool.finish(); } catch(std::exception &ex) { std::cout<<"An exception was thrown while processing data. Exception says: " << ex.what() << std::endl; std::exit(1); } for (unsigned int i = 0; i < nums.size(); ++i) { std::cout<<"Sum from 0 to " << nums[i] << " is: " << numsResults[i] <