64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <pthread.h>
using namespace std;
class Test
{
public:
Test(){}
~Test(){}
void func(){cout<<"Fuck it again!"<<endl;}
static void *thread_func(void *param){
Test *p = (Test *)param;
p->func();
}
void create_thread(){
pthread_t thread;
int res = pthread_create(&thread,NULL,thread_func,this);
cout<<res<<endl;
}
};
int main(int argc,char *argv[]){
Test test;
test.create_thread();
return 0;
}
#include <iostream>
#include <pthread.h>
using namespace std;
void *thread_func(void *param);
class Test
{
public:
Test(){}
~Test(){}
void func(){cout<<"Fuck it again!"<<endl;}
void create_thread(){
pthread_t thread;
int res = pthread_create(&thread,NULL,thread_func,this);
cout<<res<<endl;
}
};
void *thread_func(void *param){
Test *p = (Test *)param;
p->func();
}
int main(int argc,char *argv[]){
Test test;
test.create_thread();
return 0;
}