I don't know what am I doing wrong in the following function. I am trying to return an array but it Seg Faults at while loop in the compute_average. I am using a structure to initialize the begin and the last word and used in the function "compute_average" You can assume the compute_average function works fine which was already there but I changed the code when using the structure or "first" and "second" value.
typedef struct parallel{
unsigned long first, second;
}Parallel;
return final_array;
}
Your argument to
pthread_join
is wrong. You are, in effect, doing this:You need to supply the address of a
void *
variable (and technically you should capture the return value ofpthread_join
itself, in case it fails, although here it won't):If
error==0
after this,ary1
will contain the value returned from the thread, andarray1 = ary1
will suffice to make it useful (no cast is needed there).(As ldav1s noted, the size is wrong too. You may want to augment the code to return more than just one pointer. Or you could fill in a data structure supplied by the thread's caller. [I'm making various guesses here about how you might implement multiple threads, in the end. The guesses may be wrong. :-) ])