#include <stdio.h>
#include <pthread.h> pthread_t tid[];
void *func_2(void *arg);
void *func_1(void *arg)
{ //为函数func_2创建线程
printf("Starting func_1\n");
pthread_create(&tid[], NULL, func_2, NULL);
//tid[0]将自己挂起,等待线程tid[1]的结束
pthread_join(tid[], NULL);
} void *func_2(void *arg)
{
printf("Starting func_2\n");
sleep();
pthread_exit(NULL);
} int main()
{ //为函数func_1创建线程并将其分离
pthread_create(&tid[], NULL, func_1, NULL);
// pthread_detach(tid[0], NULL); //分离
pthread_detach(tid[]); //分离
//主线程不退出,但这两个现成的资源都可以释放掉
// return 0;
pthread_exit(NULL);
}

在main()函数中,如果采用return 0,则没有任何输出就退出了;而如果采用的是pthread_exit(NULL),则打印出消息

最新文章

  1. .Net Core MVC 网站开发(Ninesky) 2.3、项目架构调整-控制反转和依赖注入的使用
  2. VS调试程序时一闪而过的问题-解决方法(网上搜集)
  3. [原创]使用Gradle的插件EnIDE build的时候,输出的中文总是乱码。
  4. salesforce 零基础开发入门学习(十四)salesforce中工厂模式的运用
  5. 2014.10.09 Andrew 学习 WPF(刘铁锰) 笔记分享
  6. SSH WebShell: SSH在线WEB管理器安装教程 - VPS管理百科
  7. MySQL ProxySQL读写分离实践
  8. [转] .NET领域驱动设计—看DDD是如何运用设计模式颠覆传统架构
  9. shell 安装使用VIM
  10. Kubernetes+Docker的云平台在CentOS7系统上的安装
  11. Net dll组件版本兼容问题
  12. Syntactic and Semantic Errors
  13. nwjs 实现的 分块上传
  14. Java I/O 应用程序设计
  15. Python 爬验证码
  16. Sql Server 2008 清理日志文件
  17. 基本SQL命令
  18. android 9 patch
  19. xcode恢复语法高亮
  20. JavaScript工作机制:V8 引擎内部机制及如何编写优化代码的5个诀窍

热门文章

  1. webstorm的下载、破解、与汉化
  2. HDU 3622 Bomb Game(2-sat)
  3. poj1426 Find The Multiple (DFS)
  4. MVC通过重写OnActionExecuting获取控制器,方法和域
  5. Vue-基础(一)
  6. Java jvisualvm简要说明(转)
  7. 你了解SEO中的时效性吗?
  8. Cesium截图功能
  9. MySQL UNSIGNED
  10. qt学习(二):启动画面