PDA

View Full Version : [C] problema compilazione pthread_create()


noodles83
09-06-2009, 15:28
Ottengo un warning compilando con "-Wall -pedantic"

warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type

non capisco dove sia il problema, mi dareste una mano per capire dove sbaglio? vi riporto un pezzo di codice...


void* work_func(sthread_t* info);


int main(int argc, char* argv[]){

......

array[threadIndex].index=threadIndex;
array[threadIndex].ch=clientSocket;
array[threadIndex].dir=mydir;
array[threadIndex].dir_name=argv[1];

if(pthread_create(&(array[threadIndex].id),NULL, work_func, (sthread_t*)&array[threadIndex])!=0){
fprintf(stderr,"Errore: dserver/pthread_create\n");
exit(EXIT_FAILURE);
}else {
printf("%d) Creating new thread for a new client\n",threadIndex);
threadIndex++;
}
.....

}


poche righe sotto... c'è la funzione del thread.


/*FUNZIONE dei THREADS DEDICATI*/
void* work_func(sthread_t* info){


// corpo della funzione


pthread_exit(NULL);
}

:confused:

blu_eye4
09-06-2009, 16:25
printf("%d) Creating new thread for a new client\n",threadIndex);
threadIndex++;


manca una parentesi aperta... :stordita: sarà questo?

noodles83
09-06-2009, 16:28
mmm... non manca nessuna parentesi aperta. :D

who_is4tlas
14-06-2009, 11:49
La signature di pthread_create() è questa:

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);

Il terzo parametro è un puntatore ad una funzione di questo tipo:

void *foo(void *);