pthread_exit
当主线程调用pthread_exit时,其余线程不退出,继续执行
当主线程调用exit/或return时,其余线程退出,整个进程都退出了。
#include <pthread.h>
#include <stdio.h>
#include<stdlib.h>
#include <unistd.h> #include <pthread.h> void* new_thread(void* arg)
{
while()
{
printf("new thread\n");
fflush(stdout);
sleep();
}
return NULL;
} int main(void)
{
pthread_t tid; int err = pthread_create(&tid, NULL, new_thread, (void *));
sleep();
printf("call pthread_exit\n");
fflush(stdout);
//pthread_exit(NULL); return ;
}
当mian中条用pthread_exit 时,new_thread 继续运行。
当main中直接return时,new_thread 停止运行,进程退出了。
pthread_exit的更多相关文章
- Linux多线程实例练习 - pthread_exit() 与 pthread_join()
Linux多线程实例练习 - pthread_exit 与 pthread_join pthread_exit():终止当前线程 void pthread_exit(void* retval); pt ...
- 多线程:pthread_exit,pthread_join,pthread_self
/*exit_join_id.c*/ #include<pthread.h> #include<stdio.h> void* eji(void* agr) { printf(& ...
- pthread_exit在main线程中的用处
在main线程中调用pthread_exit会起到只让main线程退出,但是保留进程资源,供其他由main创建的线程使用,直至所有线程都结束,但在其他线程中不会有这种效果 https://stacko ...
- 线程相关函数(1)-pthread_create(), pthread_join(), pthread_exit(), pthread_cancel() 创建取消线程
一. pthread_create() #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_a ...
- 线程正常终止pthread_exit,pthread_join,pthread_kill,pthread_cancel,sigwait,sigaddset
int pthread_join(pthread_t thread, void **retval); int pthread_detach(pthread_t thread); void pthrea ...
- pthread_exit pthread_join
int pthread_join(pthread_t thread, void **retval); int pthread_detach(pthread_t thread); void pthrea ...
- pthread_create & pthread_exit
http://www.cppblog.com/saha/articles/189802.html 1. pthread_create #include <pthread.h> ...
- pthread_join/pthread_exit的用法解析
官方说法: 函数pthread_join用来等待一个线程的结束.函数原型为: extern int pthread_join __P ((pthread_t __th, void **__thread ...
- pthread_join/pthread_exit的使用方法解析
官方说法: 函数pthread_join用来等待一个线程的结束.函数原型为: extern int pthread_join __P ((pthread_t __th, void **__thread ...
随机推荐
- InfluxDb系列:几个关键概念(主要是和关系数据库做对比)
https://docs.influxdata.com/influxdb/v0.9/concepts/key_concepts/ #,measurement,就相当于关系数据库中的table,他就是 ...
- 有关JVM内存
程序计数器是一个比较小的内存区域,用于指示当前线程所执行的字节码执行到了第几行,是线程隔离的 Java方法执行内存模型,用于存储局部变量,操作数栈,动态链接,方法出口等信息,是线程隔离的 原则上讲,所 ...
- 虚拟机安装Mac OS X ----- VM12安装Mac OS X
Windows下虚拟机安装Mac OS X -– VM12安装Mac OS X 10.11 随着Iphone在国内大行其道,越来越多的开发者涌入iOS开发大军 中,但都苦于没有苹果机,本文即将介绍WI ...
- Sublime Text 之运行 ES6 (基于babel)
本文同步自我的个人博客:http://www.52cik.com/2015/10/21/sublime-text-run-es6.html 之前在博客园里写过一篇<Sublime Text 之运 ...
- 【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
距上次写博客还是有点久了,中间有个写的念头,不过由于不知道写什么也就放弃了. 14年4月份第一份前端工作到现在也有一年半之久了,自己对前端的热爱相对于一年前是有过之而无不及.一年半的时间里自己也成长了 ...
- 『随笔』WCF开发那些需要注意的坑
执行如下 批处理:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\svcutil.exe" http://127.0.0.1: ...
- js方式清空表单数据的两种方式
方法1:遍历页面元素 /* 清空FORM表单内容 id:表单ID*/ function ClearForm(id) { var objId = document.getElementByI ...
- openwrt的路由器重置root密码
家里路由器刷了openwrt,结果长期没登录,忘了root密码. 很容易就找到了这里介绍的办法 http://www.openwrt.org.cn/bbs/thread-12327-1-1.html ...
- [USACO2002][poj1947]Rebuilding Roads(树形dp)
Rebuilding RoadsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 8589 Accepted: 3854Descrip ...
- JS函数表达式
导图