I'm not familiar with returning things from pthread start routines, so I've come to SO for some assistance.
The start routine will calculate some prime numbers of a given range, store them in an array of ints and then return that array to the main where it will be printed.
If there is a different way to go about accomplishing this, I'd love to hear it!
Here's what I've got:
//start routine
void *threadCreate(void* arg){
int threadNumber = threadCount;
threadCount++;
Data *data;
data = (struct Data*)arg;
int primes[data->end]; //I don't know how many primes we will have, but I think if I use the end range value as a size it will be more than enough.
int k = 0; //Index of the int array
printf("Thread #%d results: ", threadNumber);
for (int i = data->start; i <= data->end; i++){
if (isPrime(i)){
printf("%d ", i);
primes[k] = i;
k++;
}
}
printf("\n");
pthread_exit((void*)primes);
}
//in main, this is where we print our array
//I don't know the correct way to get this array
void *retval;
pthread_join(tid, &retval);
//im aware the next part is more than likely incorrect, I am just trying to illustrate what I am trying to do
for (int i = 0; i < len((int [])retval); i++){
printf("%d ", (int[])retval[i]);
}