在pthread中附加类的成员函数

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

如何在上面的代码中传递类的成员函数。

你需要创建一个免费的extern "C"函数作为蹦床:

 class foo { public: void *thread_func(); }; extern "C" void *thread_func(void *arg) { return static_cast(arg)->thread_func(); } foo f; pthread_create(..., thread_func, &f);