Possible Duplicate:
pthread Function from a Class
I am getting an error (“Can not convert …..”) and I think the third argument in the pthread_create call is wrong. I know the type of the third argument should be (void*)*(void *) but I am still getting an error.
void ServerManager::Init(){
pthread_t thread;
pthread_create(&thread, NULL, AcceptLoop, (void *)this);
}
I have declared like this and I am trying to call the function below
void* ServerManager::AcceptLoop(void * delegate){
}
Please let me know how to fix this..
Thanks in advance.
To be portable the callback function must use the C ABI;
Edit: Based on comment
pthread_join()
This will wait for a particular thread to exit. The thread that called pthread_create() can call pthread_join() to wait for the child to finish. A good place for this would(might) be to put the join in the destructor of the ServerManager.
pthread_cancel()
pthread_cancel() is an asynchronous request for the thread to stop. The call will return immediately (thus does not mean the thread is dead yet). It is unspecified how quickily it will stop executing your code but it should execute some tidy handlers and then exit. It is a good idea to wait for a cancelled thread using pthread_jon().