- #include<iostream>
-
-
#include<pthread.h>
-
-
using namespace std;
-
-
-
-
void* thread_info(void*)
-
-
{
-
-
cout<<"thread_info function!"<<endl;
-
-
}
-
-
-
-
int main(void)
-
-
{
-
-
pthread_t thread_id;
-
-
int ret;
-
-
ret=pthread_create(&thread_id,NULL,thread_info,NULL);
-
-
if(ret==-1)
-
-
{
-
-
cout<<"cannot creat new thread!"<<endl;
-
-
return 1;
-
-
}
-
-
sleep(5);
-
-
return 0;
-
-
}
终端:
[zxq@m1 pthread_test]$ g++ -o main main.cpp -lpthread
[zxq@m1 pthread_test]$ ./main
thread_info function!
[zxq@m1 pthread_test]$
在Eclipse中编译需要以下处理:
Project->Properties->C/C++ Build->Settings->GCC C++ Linker->Libraries
在Libraries(-l)中添加pthread
阅读(406) | 评论(0) | 转发(0) |