fptr
is a function pointer, and even if I pass fptr
instead of threadFunc
in pthread_create()
it still works.
Shouldn't it be *fptr
that must be passed instead of just fptr
? How is it working with fptr
instead of *fptr
?
#include <iostream>
#include <thread>
using namespace std;
void* threadFunc(void *arg){
cout<<"Thread FUnction\n";
pthread_exit(NULL);
}
int main(){
pthread_t my_thread;
void* (*fptr)(void*);
fptr=threadFunc;
int ret = pthread_create(&my_thread,NULL,fptr,NULL);
if(ret){
printf("Error creating thread\n" );
exit(EXIT_FAILURE);
}
pthread_exit(NULL);
}