I am trying to create a thread using pthread. So far I have this:
sample.h:
void* ReceiveLoop(void*);
pthread_t mythread;
sample.cpp:
void* ReceiveLoop(void*) {
cout<<"whatever";
}
void sample::read() {
pthread_create(&mythread, NULL, ReceiveLoop, NULL);
}
Which I think is ok having read some posts about this. I have also tried with
pthread_create(&mythread, NULL, &ReceiveLoop, NULL);
But I get this:
.cpp:532: error: no matches converting function 'ReceiveLoop' to type 'void* (*)(void*)'
.cpp:234: error: void* sample::ReceiveLoop(void*)
Anyone can help me? Thanks.
I recall a few idiosyncrasies between older versions of gcc/g++ with regards to errors like this. You didn’t indicate the compiler you were using.
Go ahead and give the void* parameter passed to ReceiveLoop a name:
For some reason, I seem to recall that’s the only way I could get a particular piece of code to compile on some random compiler even though the parameter passed in wasn’t actually used.
Also, if ReceiveLoop is a member function of a class, it needs to be declared static.