I wrote the following code which gives an error;
ipt.cpp: In function ‘bool isprimet(long unsigned int, int)’: ipt.cpp:28:86: error: no match for call to ‘(std::thread) (void (&)(long unsigned int, long unsigned int, long unsigned int, bool), const long unsigned int&, long unsigned int&, long unsigned int&, unsigned int&)’ for (unsigned long c=0;c
What am I doing wrong?
#include <iostream>
#include <thread>
#include <math.h>
using namespace std;
void ipt(const unsigned long number, const unsigned long root, const unsigned long threadid, bool &result)
{
result=true;
for (unsigned long c=5+threadid*6;c<=root;c+=(threadid+1)*6)
{
if(number % c-1 == 0) {result=false; break;};
if(number % c+1 == 0) {result=false; break;};
}
}
bool isprimet(const unsigned long number, const int nthreads)
{
if (number > 1)
{
if (number > 3)
{
if (number % 2 == 0) return false;
if (number % 3 == 0) return false;
unsigned int results[nthreads];
unsigned long root=(unsigned long)floor(sqrt(number))+1;
thread t[nthreads];
for (unsigned long c=0;c<nthreads;c++) t[c](ipt, number, root, c, results[c]);
for (unsigned long c=0;c<nthreads;c++) t[c].join();
for (unsigned long c=0;c<nthreads;c++) if (results[c]==false) return false;
return true;
}
else return true;
}
else return false;
}