有关线程
来源:互联网 发布:淘宝达人刷一万粉丝 编辑:程序博客网 时间:2024/05/20 22:38
子线程循环 3 次,接着主线程循环 6 次,接着又回到子线程循环 3 次,接着再回到主线程又循环6 次,如此循环50次,试写出代码。
#include <stdio.h>#include <pthread.h>#include <stdlib.h>int flag = 0;int count = 1;void * thread_func(void *arg){while(count < 51){if((flag > -1) && (flag < 3)){printf("%d.child pthread is running…………\n",count);count++;flag++;}else{sleep(1);}}while(count == 51){printf("child pthread exit!\n");exit(0);}}int main(){pthread_t m_thread;void * thread_result;int ret;ret = pthread_create(&m_thread,NULL,thread_func,&count);if(ret != 0){perror("thread create failed!\n");exit(EXIT_FAILURE);}while(count < 51){if((flag > 2) && (flag < 9)){printf("%d.main pthread is running…………\n",count);count++;flag++;}else{flag = 0;sleep(1);}}printf("\nwaiting for thread to finish...\n");ret = pthread_join(m_thread,&thread_result);if(ret != 0){perror("thread join failed!\n");exit(EXIT_FAILURE);} return 0;}
0 0
- 有关线程
- 有关线程
- 有关线程
- 有关线程
- 有关线程
- 和线程有关
- 线程有关(待续)
- 有关java线程同步
- 有关线程的知识点
- 线程有关知识
- 有关线程局部存储
- 有关线程方面
- 有关线程池
- 并发线程有关问题
- 有关线程地址空间
- 有关线程调度问题
- 有关线程的函数
- 有关线程的创建
- log4j2的重新加载及不同级别日志输出到不同日志文件
- 通过zabbix自动发现Tomcat服务端口
- Swift 初体验-简单值
- 我是怎么做详情页静态化的
- oracle 脚本
- 有关线程
- rBackup技术,彻底解决固态硬盘电容老化带来的安全隐患
- win8快速新建便笺
- spring集成mybatis,dbcp连接池,配置文件
- pktgen+dpdk(2.2.0)
- ;(function(window, document, $) { 的作用及解释
- spring mvc+mybatis笔记(一)
- ubuntu16 vim 支持python
- openCV图像处理之重映射