fork download
  1. #include <iostream>
  2. #include <thread>
  3. #include <vector>
  4.  
  5. int countFactors (long l) { return 0; }
  6.  
  7. void thrMain(const std::vector<long>& list, std::vector<int>& result,
  8. const int startInd, const int endInd)
  9. {
  10. for (int i = startInd; (i < endInd); i++)
  11. {
  12. result[i] = countFactors(list[i]);
  13. }
  14. }
  15.  
  16. std::vector<int> getFactorCount(const std::vector<long>& numList, const int thrCount)
  17. {
  18. // First allocate the return vector
  19. const int listSize = numList.size();
  20. const int count = (listSize / thrCount) + 1;
  21. std::vector<std::thread> thrList; // List of threads
  22. // Store factorial counts
  23. std::vector<int> factCounts(numList.size());
  24. for (int start = 0, thr = 0; (thr < thrCount); thr++, start += count) {
  25. int end = std::max(listSize, (start + count));
  26. thrList.push_back(std::thread(thrMain, std::ref(numList),
  27. std::ref(factCounts), start, end));
  28. }
  29. for (auto& t : thrList) {
  30. t.join();
  31. }
  32. // Return the result back
  33. return factCounts;
  34. }
  35.  
  36. int main () {}
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
Standard output is empty