fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. static int isPrime(int n);
  5. static int primesInRange(int min, int max){}
  6. void myRun(int min, int max, int* threads, int index);
  7.  
  8. int main()
  9. {
  10. std::thread* ths[2];
  11. int threadCount[2];
  12.  
  13. for (int i = 0; i < 2; i++)
  14. {
  15. std::thread* th = new std::thread(myRun, 0, 4, threadCount, i);
  16. ths[i] = th;
  17. }
  18.  
  19. for (int i = 0; i < 2; i++)
  20. {
  21. ths[i]->join();
  22. }
  23.  
  24. int result = 0;
  25. for (int i = 0; i < 2; i++)
  26. {
  27. result = result + threadCount[i];
  28. }
  29.  
  30. std::cout <<"text here\n";
  31. }
  32.  
  33.  
  34. void myRun(int min, int max, int* threads, int index)
  35. {
  36. threads[index] = primesInRange(min, max);
  37. }
Runtime error #stdin #stdout 0s 5532KB
stdin
Standard input is empty
stdout
Standard output is empty