I have this code:
void* ConfigurationHandler::sendThreadFunction(void* callbackData)
{
const EventData* eventData = (const EventData*)(callbackData);
//Do Something
return NULL;
}
void ConfigurationHandler::sendCancel()
{
EventData* eventData = new EventData();
eventData ->Name = "BLABLA"
pthread_t threadId = 0;
int ret = pthread_create(&threadId,
NULL,
ConfigurationHandler::sendThreadFunction,
(void*) eventData ); // args passed to thread function
if (ret)
{
log("Failed to launch thread!\n");
}
else
{
ret = pthread_detach(threadId);
}
}
I am getting a compiler error:
error: argument of type 'void* (ConfigurationHandler::)(void*)' does not match 'void* (*)(void*)'
Typical approach to your problem is to pass C++ object to pthread_create() via void pointer (this data pointer in its interface). The thread function passed will be global (possible static function) which knows that the void pointer is actually an C++ object.
Like in this example: