pthread_create from non-static member function
Posted
by Stanislav Palatnik
on Stack Overflow
See other posts from Stack Overflow
or by Stanislav Palatnik
Published on 2010-03-14T05:01:15Z
Indexed on
2010/03/14
5:05 UTC
Read the original article
Hit count: 368
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*)
© Stack Overflow or respective owner