My program needs to create some threads, but I'm stuck at pthread_join, as it always goes into the error case, because the return ( safe ) is 3, instead of 0, which I assume is the correct number in case everything goes okay.
Edit: To better explain myself, the error is that the code is entering the error handling area, when it is not supposed to, which translates for me getting a "Error waiting: Successful" message.
int main() {
pthread_t tids[NUM_THREADS];
int a, i, resultado, safe ;
char *f ;
f = (char *)malloc(sizeof(SIZEFICHEIRO));
a = randomnum(4);
f = pickfile(a, f);
for ( i=0; i<NUM_THREADS ; i++ )
{
safe = pthread_create( &tids[i] , NULL , (void *)verificador , (void *) f) ;
if ( safe != 0 )
perror ("Error creating threads");
}
for ( i=0; i<NUM_THREADS ; i++ )
{
safe = pthread_join( tids[i], (void **)&resultado ) ;
if ( safe != 0 ) // Error here
perror ("Error waiting");
printf("Result(0:Works ; -1:error) = %d\n", resultado);
}
}