Your argument to pthread_join
is wrong. You are, in effect, doing this:
pthread_join(tid, NULL);
You need to supply the address of a void *
variable (and technically you should capture the return value of pthread_join
itself, in case it fails, although here it won't):
error = pthread_join(tid, &ary1);
If error==0
after this, ary1
will contain the value returned from the thread, and array1 = 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. :-) ])