我正在使用 C++ 和 pthreads,到目前为止一切顺利。如果它是静态的,我可以访问一个类成员函数,我读过如果我将“this”作为参数传递给 pthread_create,我可以访问一个普通的类成员函数,因为 c++ 在后台执行此操作。但我的问题是我想给那个函数一个 int,我不知道如何用 pthread_create 做多个参数。
最佳答案
传递一个结构指针。
struct Arg {
MyClass* _this;
int another_arg;
};
...
Arg* arg = new Arg;
arg->_this = this;
arg->another_arg = 12;
pthread_create(..., arg);
...
delete arg;
关于c++ - pthreads 和 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2468113/