#include <iostream>
#include "test.h"
#include <pthread.h>
using namespace std;
test::test(){}
test::~test(){}
void *threadFunction(){
cout << "this is a thread"<<endl;
for(;;);
}
void *thread(void*){
int i;
for(i=0;i<3;i++){
printf("this is a pthread.\n");
}
}
int main(){
//cout << "123" << endl;
pthread_t id;
int i,ret;
ret = pthread_create(&id,NULL,thread,NULL);
if(ret!=0){
printf("create pthread error!\n");
exit(1);
}
for(i=0;i<3;i++){
printf("This is the main process.\n");
pthread_join(id,NULL);
return 0;
}
}
编译的时候的命令是:
g++ test.h test.cpp -lpthread -o test
c++ 多线程
最新推荐文章于 2024-11-07 18:36:53 发布