http://blog.csdn.net/jiaowopan/article/details/12009079

C/C++(Linux平台)

注意编译连接时需要链接pthread库,即g++ XX.cpp -o XX -lpthread

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <pthread.h>
  4. void* thread(void* v)
  5. {
  6. char ch = *(char*)v;
  7. sleep(1);
  8. putchar(ch);
  9. }
  10. int main()
  11. {
  12. pthread_t id[7];
  13. int i ,ret;
  14. char str[] = "abcdefg";
  15. for(i = 0; i < 7; ++i)
  16. {
  17. ret = pthread_create(&id[i],NULL,thread,&str[i]);
  18. if(0 != ret)
  19. {
  20. printf("create pthread error\n");
  21. i--;
  22. }
  23. }
  24. for(i = 0; i < 7; ++i)
  25. pthread_join(id[i],NULL);
  26. printf("\n");
  27. return 0;
  28. }

最新文章

  1. Maven 配置远程仓库
  2. IO多路转接select和poll
  3. trigger,triggerhandler模拟事件
  4. Ant 入门
  5. OpenJudge/Poj 1005 I Think I Need a Houseboat
  6. Linux基础1之磁盘与分区
  7. bzoj3504
  8. USB Mass Storage协议分析
  9. POJ_2769同余问题
  10. TP5使用phpmailer实现邮件发送
  11. apache配置,禁止ip访问web站点
  12. Reveal安装
  13. [原]openstack-kilo--issue(二十一) instance can&#39;t get ip 虚拟机不能得到ip(2)
  14. centos6.5官方dvd做本地yum
  15. MongoDB的数据模型
  16. iOS UI-三种简单的动画设置
  17. ASP.NET下跨应用共享Session和使用Redis进行Session托管
  18. 【自动化专题】借助firefox插件定位web元素小技巧
  19. oracle中恢复删除的表
  20. PHP5.5的新特性

热门文章

  1. maven下载与配置环境变量
  2. [小问题笔记(四)] Enum枚举类型转换为DataTable( C# )
  3. iview--2
  4. php redis 秒杀demo
  5. Angular2 中的依赖包详解
  6. Angular内提供了一个可以快速建立测试用web服务的方法:内存 (in-memory) 服务器
  7. 我的 VSCode 常用扩展
  8. 当vue路由变化时 改变导航条式样
  9. Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制
  10. C#_串口通信_SerialPort_一个最基础的串口程序