0
如何使用pthread将thread_ready_function
调用为注释的线程?我需要用类对象调用它(在现实世界中,函数使用之前设置的属性)。使用pthread调用对象的成员函数
MWE
#include <iostream>
#include <pthread.h>
class ClassA
{
public:
void * thread_ready_function(void *arg)
{
std::cout<<"From the thread"<<std::endl;
pthread_exit((void*)NULL);
}
};
class ClassB
{
ClassA *my_A_object;
public:
void test(){
my_A_object = new ClassA();
my_A_object->thread_ready_function(NULL);
// my_A_object->thread_ready_function(NULL);
//^
// I want to make that call into a thread.
/* Thread */
/*
pthread_t th;
void * th_rtn_val;
pthread_create(&th, NULL, my_A_object.thread_ready_function, NULL);
pthread_join(th, &th_rtn_val);
*/
}
};
int main()
{
ClassB *my_B_object = new ClassB();
my_B_object->test();
return 0;
}
你可以使用C++ 11线程吗? – Brahim
我会看看C++ 11.但是因为它的支持很棘手,我想,我想知道是否有一种方法可以使用'pthread'来实现这一点[ – JeanRene
] [pthread Function from a class](http:// stackoverflow .COM /问题/ 1151582 /并行线程功能,从-A级) – Ionut