The objective of this main function is to find the number of prime numbers in a range using threading to divide the problem into the selected number of threads. I'm having issues with std::thread
and getting an error because of the arguments. I'm not sure of how to fix it. Any help would be greatly appreciated.
Here is the error:
error: no matching function for call to 'std::thread::thread(void (&)(int, int, int*, int), int&, int&, int [numThreads], int&)' std::thread* th = new std::thread(myRun, minThread, maxThread, threadCount, i);
#include <iostream>
#include <thread>
static int isPrime(int n);
static int primesInRange(int min, int max);
void myRun(int min, int max, int* threads, int index);
int main()
{
std::thread* ths[2];
int threadCount[2];
for (int i = 0; i < 2; i++)
{
std::thread* th = new std::thread(myRun, min, max, threadCount, i);
ths[i] = th;
}
for (int i = 0; i < 2; i++)
{
ths[i]->join();
}
int result = 0;
for (int i = 0; i < 2; i++)
{
result = result + threadCount[i];
}
std::cout <<"text here\n";
}
void myRun(int min, int max, int* threads, int index)
{
threads[index] = primesInRange(min, max);
}