Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157640
  • 博文数量: 76
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 15:15
文章分类

全部博文(76)

文章存档

2012年(2)

2011年(74)

我的朋友

分类: C/C++

2011-11-25 21:06:17

  1. #include<iostream>

  2. #include<pthread.h>

  3. using namespace std;

  4.  

  5. void* thread_info(void*)

  6. {

  7. cout<<"thread_info function!"<<endl;

  8. }

  9.  

  10. int main(void)

  11. {

  12. pthread_t thread_id;

  13. int ret;

  14. ret=pthread_create(&thread_id,NULL,thread_info,NULL);

  15. if(ret==-1)

  16. {

  17. cout<<"cannot creat new thread!"<<endl;

  18. return 1;

  19. }

  20. sleep(5);

  21. return 0;

  22. }

终端:

[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

阅读(382) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~