pthread_create from non-static member function
- by Stanislav Palatnik
This is somewhat similiar to this : http://stackoverflow.com/questions/1151582/pthread-function-from-a-class
But the function that's getting called in the end is referencing the this pointer, so it cannot be made static.
void * Server::processRequest()
{
std::string tmp_request, outRequest;
tmp_request = this->readData();
outRequest = this->parse(tmp_request);
this->writeReply(outRequest);
}
void * LaunchMemberFunction(void * obj)
{
return ((Server *)obj)->processRequest();
}
and then the pthread_create
pthread_create(&handler[tcount], &attr, (void*)LaunchMemberFunction,(void*)&SServer);
errors:
SS_Twitter.cpp:819: error: invalid conversion from void* to void* ()(void)
SS_Twitter.cpp:819: error: initializing argument 3 of int pthread_create(pthread_t*, const pthread_attr_t*, void* ()(void), void*)