Linux多线程实例练习 - pthread_exit() 与 pthread_join()
Linux多线程实例练习 - pthread_exit 与 pthread_join
pthread_exit():终止当前线程
void pthread_exit(void* retval);
pthread_join():阻塞当前的线程,直到另外一个线程运行结束
int pthread_join(pthread_t thread, void **retval);
1、代码 xx_pthread_exit.c
#include <pthread.h>
#include <stdio.h>
#include <unistd.h> #define debug_Msg(fmt, arg...)\
do{\
printf("%s %d : ", __FILE__, __LINE__);\
printf(fmt, ##arg);\
}while() void * doPrint(void *arg)
{
debug_Msg("%s\n", (char*)arg);
char * p = "thread is over";
pthread_exit(p);
}
int main()
{
pthread_t pid;
char * pt = "hello pthread";
pthread_create(&pid, NULL, doPrint, pt);
void * p = NULL;
pthread_join(pid, &p);
debug_Msg("return of thread : [%s]\n", (char*)p); return ;
}
2、CentOS 下编译通过
g++ -g -c -o xx_pthread_exit.o xx_pthread_exit.c
g++ -g -o xx_pthread_exit xx_pthread_exit.o -lpthread
3、运行结果
$ ./xx_pthread_exit
xx_pthread_exit.c : hello pthread
xx_pthread_exit.c : return of thread : [thread is over]
Linux多线程实例练习 - pthread_exit() 与 pthread_join()的更多相关文章
- Linux多线程实例练习 - pthread_cancel()
Linux多线程实例练习 - pthread_cancel 1.代码 xx_pthread_cancel.c #include <pthread.h> #include <stdio ...
- Linux多线程实例练习 - pthread_create()
Linux多线程实例练习 pthread_create():创建一个线程 int pthread_create(pthread_t *tidp, const pthread_attr_t *attr, ...
- Linux多线程实例解析
Linux系统下的多线程遵循POSIX线程接口,称为 pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.顺便说一下,Linux ...
- Linux多线程实例 定时重启httpd和mysqld
#include <stdio.h> #include <pthread.h> void *start_routine(void *arg) { while(1) { syst ...
- Linux多线程编程实例解析
Linux系统下的多线程遵循POSIX线程接口,称为 pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.顺便说一下,Linux ...
- 笔记整理--Linux多线程
Unix高级环境编程系列笔记 (2013/11/17 14:26:38) Unix高级环境编程系列笔记 出处信息 通过这篇文字,您将能够解答如下问题: 如何来标识一个线程? 如何创建一个新线程? 如何 ...
- Linux多线程编程初探
Linux线程介绍 进程与线程 典型的UNIX/Linux进程可以看成只有一个控制线程:一个进程在同一时刻只做一件事情.有了多个控制线程后,在程序设计时可以把进程设计成在同一时刻做不止一件事,每个线程 ...
- 【操作系统作业-lab4】 linux 多线程编程和调度器
linux多线程编程 参考:https://blog.csdn.net/weibo1230123/article/details/81410241 https://blog.csdn.net/skyr ...
- Linux多线程编程之详细分析
线程?为什么有了进程还需要线程呢,他们有什么区别?使用线程有什么优势呢?还有多线程编程的一些细节问题,如线程之间怎样同步.互斥,这些东西将在本文中介绍.我见到这样一道面试题: 是否熟悉POSIX多线程 ...
随机推荐
- Spring XML配置文件示例(一)——<Servlet name>-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- NBU expired Media,Media ID not found in EMM database
Subject:When attempting to expire a media in Veritas NetBackup (tm) 6.0 with the bpexpdate command, ...
- wp8 入门到精通 Utilities类 本地存储+异步
public class CCSetting { public async static void AddOrUpdateValue<T>(string key, T value) { t ...
- [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决
转自:http://blog.csdn.net/wanglei2258/article/details/24961233 [CentOS]安装软件:/lib/ld-linux.so.2: bad EL ...
- [Unity3D插件]2dtoolkit系列二 动画精灵的创建以及背景图的无限滚动
经过昨天2dtoolkit系列教程一的推出,感觉对新手还有有一定的启发作用,引导学习使用unity 2dToolKit插件的使用过程,今天继续系列二——动画精灵的创建,以及背景图的无限循环滚动,在群里 ...
- easyui tree折叠
标签 <div id="buildDiv" data-options="region:'center'" title="楼栋权限" s ...
- zoj 3471(状态压缩)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4257 dp[state]表示当前状态为state时的所能获得的最大值 ...
- POJ 2464 Brownie Points II(树状数组)
一开始还以为对于每根竖线,只要与过了任意一点的横线相交都可以呢,这样枚举两条线就要O(n^2),结果发现自己想多了... 其实是每个点画根竖线和横线就好,对于相同竖线统计(一直不包含线上点)右上左下总 ...
- input的placeholder文字颜色修改
input::-webkit-input-placeholder { color: #D6D0CA !important; /* WebKit browsers / } input:-moz-plac ...
- POJ3613 Cow Relays(矩阵快速幂)
题目大概要求从起点到终点恰好经过k条边的最短路. 离散数学告诉我们邻接矩阵的k次幂就能得出恰好经过k条路的信息,比如POJ2778. 这题也一样,矩阵的幂运算定义成min,而min满足结合律,所以可以 ...