I am trying to create multiple threads that each thread calculates a prime. I am trying to pass the second argument to a function using thread creation. It continues to cause errors.
void* compute_prime (void* arg, void* arg2) {
here is my main () with thread creation. & primeArray [i] after & max_prime gives me errors.
for(i=0; i< num_threads; i++) { primeArray[i]=0; printf("creating threads: \n"); pthread_create(&primes[i],NULL, compute_prime, &max_prime, &primeArray[i]); thread_number = i; //pthread_create(&primes[i],NULL, compPrime, &max_prime); } /* join threads */ for(i=0; i< num_threads; i++) { pthread_join(primes[i], NULL); //pthread_join(primes[i], (void*) &prime); //pthread_join(primes[i],NULL); //printf("\nThread %d produced: %d primes\n",i, prime); printf("\nThread %d produced: %d primes\n",i, primeArray[i]); sleep(1); }
the error i get is:
myprime.c: In function âmainâ: myprime.c:123: warning: passing argument 3 of âpthread_createâ from incompatible pointer type /usr/include/pthread.h:227: note: expected âvoid * (*)(void *)â but argument is of type âvoid * (*)(void *, void *)â myprime.c:123: error: too many arguments to function âpthread_createâ
It works fine if I take out the second argument.
user249375
source share