I'm trying to compile my program on the command line and I got this error. It was pointing to the pthread_create line in the following code. I have the correct import for pthreads and I am running on Ubuntu so I know that's not the problem. Otherwise, I'm clueless about what's going on.
int main() {
pthread_t thinker;
if(pthread_create(&thinker, NULL, thinker, NULL)) {
perror("ERROR creating thread.");
}
pthread_join(thinker, NULL);
return 0;
}
The signature of thread creation is:
int pthread_create(pthread_t * thread,
const pthread_attr_t * attr,
void * (*start_routine)(void *),
void *arg);
If you see in your code, you are passing thinker
as 3rd param which is not compatible with void * (*start_routine)(void *)
. It should be function pointer. It should be:
void *callback_function( void *ptr ){}
pthread_create(&thinker, NULL, callback_function, NULL)