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);
Here is the code:
#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()
{
int min = 0;
int max = 3;
int numThreads = 1;
std::thread* ths[numThreads];
int threadCount[numThreads];
int minThread = 0;
int maxThread = 0;
int formerMax = 0;
for (int i = 0; i < numThreads; i++)
{
if (i == 0)
{
minThread = min;
maxThread = min + (max - min)/numThreads;
formerMax = maxThread;
}
else
{
minThread = formerMax + 1;
maxThread = minThread + (max - min)/numThreads;
formerMax = maxThread;
}
if (maxThread > max)
{
maxThread = max;
}
std::thread* th = new std::thread(myRun, minThread, maxThread, threadCount, i);
ths[i] = th;
}
}
void myRun(int min, int max, int* threads, int index)
{
threads[index] = primesInRange(min, max);
}