Reputation: 159
I have created pthread as follows:
void function1(void *s) {
start = (*(int *)s ;
}
pthread_t threads[numthreads];
int ids[numthreads];
for (i = 0; i < numthreads; i++) {
ids[i] = i;
int * p = &ids[i] ;
pthread_create(&threads[i], NULL, function1, (void *)p);
}
But this is giving me error:
>> mpicc -o hprogram hprogram.c
warning: incompatible pointer types passing 'void (void *)' to
parameter of type 'void * _Nullable (* _Nonnull)(void * _Nullable)'
[-Wincompatible-pointer-types]
pthread_create(&threads[i], NULL, function1, (void *)...
^~~~~~~~~~
/usr/include/pthread.h:328:31: note: passing argument to parameter here
void * _Nullable (* _Nonnull)(void * _Nullable),
^
1 warning generated.
This is an mpi program and im creating a hybrid mpi using pthreads.
Upvotes: 2
Views: 5226
Reputation: 595961
pthread_create()
expects a pointer to a function that takes a void*
as input and returns a void*
as output, but your function returns a void
instead. You just need to add a *
to the return type, and add a return
statement, eg:
void* function1(void *s) {
start = *(int *)s;
return NULL; // <-- or whatever you want
}
Upvotes: 6