在pthread的一类附加成员函数 [英] Attaching Member function of a class in pthread
本文介绍了在pthread的一类附加成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pthread_t thread1;
pthread_create(&thread1,NULL,.......,NULL);
// Here I want to attach a thread to a member function of class
我如何传递一个类的成员函数在上面code。
How can I pass the member function of a class in the above code.
推荐答案
您需要创建一个免费的的externC
函数作为蹦床:
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);
这篇关于在pthread的一类附加成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文