c 多线程,多进程 学习
来源:互联网 发布:mac一般用什么办公软件 编辑:程序博客网 时间:2024/05/22 17:32
#include<stdio.h>#include<pthread.h>#include<string.h>#include<sys/types.h>#include<unistd.h>/*int x = 0;pthread_mutex_t tl;void *thr_fn(void *arg){ int a = 0; for (a = 0; a <= 500; a++) { pthread_mutex_lock(&tl); printf("fn1 locked\n"); x += a; sleep(3); pthread_mutex_unlock(&tl); printf("fn1 unlock\n"); } return (void *)0;}void *thr_fn2(void *arg){ int a = 0; for (a = 501; a <= 1000; a++) { pthread_mutex_lock(&tl); printf("fn2 locked\n");// printf("fn2 do\n"); x += a; sleep(1); pthread_mutex_unlock(&tl); printf("fn2 unlock\n"); } pthread_exit(arg);}int main(){ pthread_mutex_init(&tl, NULL); pthread_t ntid; pthread_create(&ntid, NULL, thr_fn, NULL); pthread_t ntid2; pthread_create(&ntid2, NULL, thr_fn2, NULL); pthread_join(ntid, NULL); pthread_join(ntid2, NULL); printf("%d\n" , x); return 0;}*/int main(){ int x = 1023; printf("main : %d\r\n", getpid()); pid_t fork_return = fork(); printf("fork_return = %d\r\n", fork_return); if(0 == fork_return) { printf("child : %d\r\n", getpid()); sleep(1); printf("child : x = %d, %d\r\n", (int)&x, x); x += 1000; sleep(3); printf("child : x = %d\r\n", x); } else if(fork_return > 0) { printf("parent : %d\r\n", getpid()); sleep(1); printf("parent : x = %d, %d\r\n", (int)&x, x); x += 10000; sleep(3); printf("parent : x = %d\r\n", x); } return 0;}
0 0
- c 多线程,多进程 学习
- 【学习笔记】C/S架构与多进程多线程
- linux c 多进程多线程比较
- C#--多进程多线程访问数据库
- C/S架构与多进程多线程
- java学习3、初学多线程、多进程
- Python 多进程/多线程 学习笔记
- 多线程与多进程编程学习整理
- Android多线程多进程学习网址
- python多进程与多线程学习总结
- 【爬虫学习】多进程,多线程处理
- 多线程学习进程
- Linux系统C/C++:多线程和多进程
- 【UnixC多线程\进程】多线程和多进程C代码及测试截图
- Linux C进程与多线程
- linux下的C\C++多进程多线程编程
- C语言实现多线程和多进程服务器
- 多线程之互斥锁(By C++)与多进程
- webView loadData 中文乱码问题
- Cocos2d-x 3.0多线程异步资源加载
- 1407231857-hd-Problem A .cpp
- hdu 2196 树形dp
- poj2796--Feel Good(单调栈求区间问题)
- c 多线程,多进程 学习
- github manual
- LeetCode Unique Binary Search Trees--动态规划思想
- WebDriver支持多浏览器
- 将Asp.Net网站发布到IIS的四种方法及注意事项
- 云计算相关术语
- 写入txt 中文
- 【服务器架构】Skynet 设计综述
- 2013蓝桥杯预选:第39阶台阶