pthread多线程
来源:互联网 发布:linux telnet服务开启 编辑:程序博客网 时间:2024/05/18 01:19
int pthread_join(pthread_t thread, void **retval);
返回值:若成功则返回0,否则返回错误编号。
调用该函数的线程将一直阻塞,直到指定的线程thread调用pthread_exit,从启动例程中返回或者被取消。
看如下程序:
#include <stdio.h>#include <pthread.h>void* printMsg1(void *data){printf("the thread 1 id is %u\n",(unsigned int)pthread_self());sleep(5);}void* printMsg2(void *data){printf("the thread 2 id is %u\n",(unsigned int)pthread_self());}int main(){pthread_t t1,t2;pthread_create(&t1,NULL,printMsg1,NULL);pthread_join(t1,NULL);printf("I am waiting\n");pthread_create(&t2,NULL,printMsg2,NULL);pthread_join(t2,NULL);return 0;}运行结果为:
tomcat@tomcat-Lenovo-IdeaPad-Y550:~/code$ ./pthreadTest
the thread 1 id is 2745190144
I am waiting
the thread 2 id is 2745190144
在t1执行完毕后,才打印出了I am waiting。说明程序在pthread_join处一直阻塞等待t1线程结束。
0 0
- Pthread多线程
- pthread多线程
- 多线程pthread
- 多线程pthread
- pthread/Linux多线程编程
- pthread多线程编程
- pthread多线程编程整理
- Pthread多线程超时取消
- linux多线程pthread
- pthread多线程编程
- Linux 多线程 pthread
- pthread多线程编程
- pthread创建多线程
- pthread/Linux多线程编程
- pthread多线程编程
- pthread多线程的创建
- Pthread:POSIX 多线程程序设计
- linux多线程 pthread用法
- C#中的集合
- 卷二 Dalvik与Android源码分析 第二章 进程与线程 2.2 Dalvik线程创建机制 图书版试读--请勿转发
- mysql in 子查询 效率慢 优化
- wpf样式
- DataGridView 列宽和行高自动调整的设定
- pthread多线程
- mqtt消息推送中间件服务器软件评价
- 索引器
- servlet线程安全问题——ThreadLocal模式
- IDE还是编辑器
- 泛型
- Javascript RegExp 常用正则使用收集
- 执行ajax返回代码中的脚本,支持document.write
- ../的路径问题