我有這樣的代碼:在pthread_create問題
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);
}
}
我得到一個編譯器錯誤:
error: argument of type 'void* (ConfigurationHandler::)(void*)' does not match 'void* (*)(void*)'
你不能安全地傳遞一個C++方法 - 即使是一個靜態方法 - 作爲一種常規來'pthread_create'。 –
什麼是更好的方法?我如何才能實現上述功能? – Kam