程序实验:-多线程编程---实验报告
(20页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
17.90 积分
嵌入式操作系统—多线程-实验报告 (11-多线程编程)程序实验二:程序实验二:11-多线程编程实验多线程编程实验专业班级专业班级 实验日期实验日期 5.21 姓名姓名 学号学号 实验一(实验一(p284::11-thread.c))1、软件功能描述、软件功能描述创建 3 个线程,让 3 个线程重用同一个执行函数,每个线程都有 5次循环,可以看成 5 个小任务,每次循环之间会有随即等待时间(1-10s)意义在于模拟每个任务到达的时间是随机的没有任何的特定规律。2、程序流程设计、程序流程设计3.部分程序代码注释.部分程序代码注释(关键函数或代码关键函数或代码)#include嵌入式操作系统—多线程-实验报告 (11-多线程编程)#include #include #define T_NUMBER 3#define P_NUMBER 5#define TIME 10.0void *thrd_func(void *arg ){int thrd_num=(int)arg;int delay_time =0;int count =0;printf(“Thread %d is staraing\n“,thrd_num);for(count=0;count #include #include#define THREAD_NUMBER 3 /*线程数*/ #define REPEAT_NUMBER 3 /*每个线程的小任务数*/ #define DELAY_TIME_LEVELS 10.0 /*小任务间的最大时间间隔*/ pthread_mutex_t mutex; void *thrd_func(void *arg) //线程函数例程 {int thrd_num = (int)arg; int delay_time = 0, count = 0; int res; //互斥锁上锁res = pthread_mutex_lock( if(res){嵌入式操作系统—多线程-实验报告 (11-多线程编程)printf(“Thread %d is starting\n“, thrd_num); pthread_exit(NULL); }printf(“Thread %d is starting\n“, thrd_num); for(count = 0; count #include #include #include#define THREAD_NUMBER3 #define REPEAT_NUMBER 3 #define DELAY_TIME_LEVELS 10.0 sem_t sem[THREAD_NUMBER]; 嵌入式操作系统—多线程-实验报告 (11-多线程编程)void *thrd_func(void *arg) { int thrd_num = (int)arg; int delay_time = 0; int count = 0; sem_wait( printf(“Thread %d is starting\n“,thrd_num); for(count = 0; count = 0; no--) { res = pthread_join(thread[no], if(!res) { printf(“Thread %d joined\n“, no); 嵌入式操作系统—多线程-实验报告 (11-多线程编程)} else { printf(“Thread %d join failed\n“, no); } sem_post( } for(no = 0; no #include #include#define REPEAT_NUMBER 3 #define DELAY_TIME_LEVELS 10.0 int finish_flag = 0; void *thrd_func(void *arg) {嵌入式操作系统—多线程-实验报告 (11-多线程编程)int delay_time = 0; int count = 0; printf(“Th is starting\n“); for(count=0; count #include #include嵌入式操作系统—多线程-实验报告 (11-多线程编程)#include #include #include #include #include#define MYFIFO“myfifo“ #defineBUFFER_SIZE3 #defineUNIT_SIZE5 #defineRUN_TIME30 #defineDELAY_TIME_LEVELS5.0int fd; time_t end_time; sem_t mutex,full,avail; void *producer(void *arg) { int real_write; int delay_time=0; while(time(NULL)
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。