Linux C多线程
来源:互联网 发布:打印文件软件 编辑:程序博客网 时间:2024/06/07 00:34
一个简单的Linux C多线程程序:主线程创建启动了2个子线程,通过pthread_join等待子线程结束。
#include <stdio.h>#include <pthread.h>#include <unistd.h>#define NUM 5int main(){ pthread_t t1, t2; void *print_msg(void *); pthread_create(&t1, NULL, print_msg, (void *)"hello"); pthread_create(&t2, NULL, print_msg, (void *)"world\n"); pthread_join(t1, NULL); pthread_join(t2, NULL);}void *print_msg(void *msg){ int i = 0; char *out = (char *)msg; for(i=0; i<NUM; i++){ printf("%s", out); fflush(stdout); sleep(2); } return NULL;}
输出:
helloworld
helloworld
helloworld
helloworld
helloworld
阅读全文
0 0
- linux c 多线程
- linux c 多线程编程
- Linux C多线程编程
- linux C 多线程
- Linux C 多线程
- Linux C 多线程编程
- linux-C编程-多线程
- Linux c 多线程 互斥量
- Linux c 多线程编程
- Linux C多线程
- linux c 多线程
- 多线程 Linux c
- 转 linux c多线程
- Linux C多线程编程
- Linux C 多线程编程
- [Linux C编程]多线程
- Linux C多线程
- linux下C语言多线程
- Android应用如何适配不同的屏幕
- hashCode()函数详解
- NSOperation浅析
- MYSQL
- 模态框回车搜索的实现
- Linux C多线程
- 判断二进制数除以3的余数
- ffmpeg录制屏幕,生成MP4视频文件开发过程
- iOS中的runtime源码简要分析(一)
- EditText显示隐藏密码
- hdu 1025 Constructing Roads In JGShining's Kingdom LIS最长上升序列
- Python实现Adaboost(decisiontree)
- 可拉伸的tabview头部视图
- 斐波那契数列