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 ...
随机推荐
- Linux Linux程序练习十二(select实现QQ群聊)
//头文件--helper.h #ifndef _vzhang #define _vzhang #ifdef __cplusplus extern "C" { #endif #de ...
- CAS 单点登录流程
经验:在网上学东西不要指望一篇文章就能让你明白——我在网上学CAS流程,看了五六篇博文,其中三篇是觉得作者表达能力不行,或者作者自己就没明白怎么回事就出来写东西,看到一半就跳过了,剩下两篇每篇看了两遍 ...
- java内部类 2016年12月13号
1.在外部类的任意位置创建内部类对象的方法: 1)从外部类的非静态方法之外的任意位置创建某个内部类的对象,必须指明这个对象所在的外部类和内部类:OuterClassName.InnerClassNam ...
- C++创建对象的两种方式
C++创建对象有两种方式,在栈上创建对象(Objects on the Stack)和在堆上创建对象(Objects on the Heap). 假设我们有以下的类: #include <str ...
- UIView的layoutSubviews和drawRect方法何时调用 ———转
转自:http://jianyu996.blog.163.com/blog/static/112114555201305113018814/ 首先两个方法都是异步执行.layoutSubviews方便 ...
- google map api v2的使用详细过程,图文并茂(原创)
上一篇中说到怎么获取key,下面来介绍怎么使用key来显示google地图 步骤1:eclipse上打开android SDK Manager,安装google play services. 步骤2: ...
- 20145222黄亚奇《Java程序设计》第10周学习总结
20145222 <Java程序设计>第10周学习总结 学习总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接 ...
- CUDA编程学习(一)
/****c code****/ #include<stdio.h> int main() { printf("Hello world!\n); ; } /****CUDA co ...
- css的img移上去边框效果及CSS透明度
css的img移上去边框效果: .v_comment img{ height:36px; height:36px; float:left; padding:1px; margin:2px; borde ...
- [BZOJ 3038]上帝造题的7分钟2(树状数组)
分析:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3038 这题看起来没办法做……但是注意到1e12只要开方8次就能到1……所以直接暴力就行 ...