Attaching class member function in pthread

pthread_t thread1; pthread_create(&thread1,NULL,.......,NULL); // Here I want to attach a thread to a member function of class 

How to pass a member function of a class in the above code.

+2
c ++ c
Mar 17 '10 at 6:16
source share
1 answer

You need to create a free extern "C" function as a trampoline:

 class foo { public: void *thread_func(); }; extern "C" void *thread_func(void *arg) { return static_cast<foo *>(arg)->thread_func(); } foo f; pthread_create(..., thread_func, &f); 
+4
Mar 17 '10 at 6:25
source share



All Articles