erstellen von thread - Argumente übergeben

Ich bin versucht, auf die Erstellung mehrerer threads, jeder thread berechnet eine Primzahl ist. Ich versuche mich zu übergeben, eine zweite argument an eine Funktion mit Hilfe thread erstellen. Es hält werfen Fehler.

void* compute_prime (void* arg, void* arg2)
{

hier ist meine main() mit der create-thread. &primeArray[i] nach &max_prime ist mir der Fehler.

 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);
}

den Fehler den ich bekomme, ist:

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â

Funktioniert es einwandfrei wenn ich mit der zweiten argument.

  • siehe Antwort unten, auch check out link für eine gute pthread-Referenz-Website.
InformationsquelleAutor | 2012-10-30
Schreibe einen Kommentar