ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:8.97KB ,
资源ID:1039581      下载积分:50 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-1039581.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(-写者问题的实现源程序_GAOQS.COM.doc)为本站会员(心***)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

-写者问题的实现源程序_GAOQS.COM.doc

1、1. /*/#include #include #include #include #include #define RWSEMKEY 75#define WWSEMKEY 90#define RSEM 78#define WSEM 79#define ZZ 80#define SEMMNI 128#define SHMKEY 166int shmid;int semid_rw;int semid_ww;int rsem;int wsem;int zz;int flags=0666;struct sembuf pbuf;struct sembuf vbuf;float w_time;float

2、 r_time;/*/struct MSGint proid;char decr;int w_time;int r_time;int *num_r;int *num_w;struct MSG msg20;void Read(struct MSG msg1)sleep(msg1.w_time);FILE *fpw=fopen(“out“,“ab“);/* printf(“the %ds (reading) progress is created!n“,msg1.proid); */* fprintf(fpw,“the %ds(reading) progress is created!n“,msg

3、1.proid);*/fclose(fpw);pbuf.sem_num=0;pbuf.sem_op=-1;pbuf.sem_flg=0;vbuf.sem_num=0;vbuf.sem_op=1;vbuf.sem_flg=0;shmid=shmget(SHMKEY,20,flags|IPC_EXCL);num_r=(int *)shmat(shmid,0,0);num_w=(int*)(num_r+8);semid_rw=semget(RWSEMKEY,1,flags|IPC_EXCL);semid_ww=semget(WWSEMKEY,1,flags|IPC_EXCL);rsem=semget

4、(RSEM,1,flags|IPC_EXCL);wsem=semget(WSEM,1,flags|IPC_EXCL);zz=semget(ZZ,1,flags|IPC_EXCL);semop(zz,semop(rsem,semop(semid_rw,(*num_r)+;if(*num_r=1)semop(wsem,semop(semid_rw,semop(rsem,semop(zz,fpw=fopen(“out“,“ab“);printf(“the %ds progress is reading!n“,msg1.proid);fprintf(fpw,“the %ds progress is r

5、eading!n“,msg1.proid);fclose(fpw);sleep(msg1.r_time);fpw=fopen(“out“,“ab“);printf(“the %ds progresss reading is end!n“,msg1.proid);fprintf(fpw,“the %ds progresss reading is end!n“,msg1.proid);fclose(fpw);semop(semid_rw,(*num_r)-;if(*num_r=0)semop(wsem,semop(semid_rw,void Write(struct MSG msg1)sleep(

6、msg1.w_time);shmid=shmget(SHMKEY,20,flags|IPC_EXCL);num_r=(int *)shmat(shmid,0,0);num_w=(int*)(num_r+8);FILE *fpw=fopen(“out“,“ab“);/* printf(“the %ds progress (writing) is created!n“,msg1.proid); */* fprintf(fpw,“the %ds progress (writing) is created!n“,msg1.proid);*/fclose(fpw);pbuf.sem_num=0;pbuf

7、.sem_op=-1;pbuf.sem_flg=0;vbuf.sem_num=0;vbuf.sem_op=1;vbuf.sem_flg=0;semid_rw=semget(RWSEMKEY,1,flags|IPC_EXCL);semid_ww=semget(WWSEMKEY,1,flags|IPC_EXCL);rsem=semget(RSEM,1,flags|IPC_EXCL);wsem=semget(WSEM,1,flags|IPC_EXCL);semop(semid_ww,(*num_w)+;if(*num_w=1)semop(rsem,semop(semid_ww,semop(wsem,

8、fpw=fopen(“out“,“ab“);printf(“the %ds progress is wrinting!n“,msg1.proid);fprintf(fpw,“the %ds progress is wrinting!n“,msg1.proid);fclose(fpw);sleep(msg1.r_time);fpw=fopen(“out“,“ab“);printf(“the %ds progresss wrinting is end!n“,msg1.proid);fprintf(fpw,“the %ds progresss wrinting is end!n“,msg1.proi

9、d);fclose(fpw);semop(wsem,semop(semid_ww,(*num_w)-;if(*num_w=0)semop(rsem,semop(semid_ww,int main()int i=0;int num;int j;float w_time;float r_time;FILE *fp=fopen(“input.txt“,“rb“);FILE *fpw=fopen(“out“,“wb+“);if(fp=NULL)printf(“Canot open the inputfile!n“);fprintf(fpw,“Canot open the inputfile!n“);f

10、close(fpw);exit(0);while(!feof(fp)fscanf(fp,“%d %c %f %f“,msgi.w_time=(int)w_time;msgi.r_time=(int)r_time;i+;fclose(fp);shmid=shmget(SHMKEY,20,flags|IPC_CREAT);num_r=(int *)shmat(shmid,0,0);num_w=(int *)(num_r+8);* num_r=0;* num_w=0;semid_rw=semget(RWSEMKEY,1,flags|IPC_CREAT);semid_ww=semget(WWSEMKE

11、Y,1,flags|IPC_CREAT);rsem=semget(RSEM,1,flags|IPC_CREAT);wsem=semget(WSEM,1,flags|IPC_CREAT);zz=semget(ZZ,1,flags|IPC_CREAT);semctl(semid_rw,0,SETVAL,1);semctl(semid_ww,0,SETVAL,1);semctl(rsem,0,SETVAL,1);semctl(wsem,0,SETVAL,1);semctl(zz,0,SETVAL,1);num=i;for(i=0;i#include #include #include #includ

12、e #define RWSEMKEY 75#define WWSEMKEY 90#define SEMMNI 128#define SHMKEY 166int shmid;int semid_rw;int semid_ww;int flags=0666;int *fpw;struct sembuf pbuf;struct sembuf vbuf;/*/*/struct MSGint proid;/*/*/char decr;/*)*/int w_time;/* */int r_time; /*/;int *num_r;int *num_w;struct MSG msg20;void Read(

13、struct MSG msg1)sleep(msg1.w_time);FILE *fpw=fopen(“out“,“ab“);/* printf(“the %ds (reading) progress is created!n“,msg1.proid);*/* fprintf(fpw,“the %ds(reading) progress is created!n“,msg1.proid);*/fclose(fpw);pbuf.sem_num=0;pbuf.sem_op=-1;pbuf.sem_flg=0;vbuf.sem_num=0;vbuf.sem_op=1;vbuf.sem_flg=0;s

14、hmid=shmget(SHMKEY,20,flags|IPC_EXCL);num_r=(int *)shmat(shmid,0,0);num_w=(int*)(num_r+8);semid_rw=semget(RWSEMKEY,1,flags|IPC_EXCL);semid_ww=semget(WWSEMKEY,1,flags|IPC_EXCL);semop(semid_rw,if(*num_r=0)semop(semid_ww,(*num_r)+;semop(semid_rw,fpw=fopen(“out“,“ab“);printf(“the %ds progress is reading

15、!n“,msg1.proid);fprintf(fpw,“the %ds progress is reading!n“,msg1.proid);fclose(fpw);sleep(msg1.r_time);fpw=fopen(“out“,“ab“);printf(“the %ds progresss reading is end!n“,msg1.proid);fprintf(fpw,“the %ds progresss reading is end!n“,msg1.proid);fclose(fpw);semop(semid_rw,(*num_r)-;if(*num_r=0)semop(sem

16、id_ww,semop(semid_rw,void Write(struct MSG msg1)sleep(msg1.w_time);FILE *fpw=fopen(“out“,“ab“);/* printf(“the %ds progress (writing) is created!n“,msg1.proid);*/* fprintf(fpw,“the %ds progress (writing) is created!n“,msg1.proid);*/fclose(fpw);pbuf.sem_num=0;pbuf.sem_op=-1;pbuf.sem_flg=0;vbuf.sem_num

17、=0;vbuf.sem_op=1;vbuf.sem_flg=0;semid_ww=semget(WWSEMKEY,1,flags|IPC_EXCL);semop(semid_ww,fpw=fopen(“out“,“ab“);printf(“the %ds progress is wrinting!n“,msg1.proid);fprintf(fpw,“the %ds progress is wrinting!n“,msg1.proid);fclose(fpw);sleep(msg1.r_time);fpw=fopen(“out“,“ab“);printf(“the %ds progresss

18、wrinting is end!n“,msg1.proid);fprintf(fpw,“the %ds progresss wrinting is end!n“,msg1.proid);fclose(fpw);semop(semid_ww,int main()int i=0;int num;int j;float w_time;float r_time;FILE *fp=fopen(“input.txt“,“rb“);FILE *fpw=fopen(“out“,“wb+“);if(fp=NULL)printf(“Canot open the inputfile!n“);fprintf(fpw,

19、“Canot open the inputfile!n“);fclose(fpw);exit(0);while(!feof(fp)fscanf(fp,“%d %c %f %f“,msgi.w_time=(int)w_time;msgi.r_time=(int)r_time;i+;fclose(fp);shmid=shmget(SHMKEY,20,flags|IPC_CREAT);num_r=(int *)shmat(shmid,0,0);num_w=(int *)(num_r+8);* num_r=0;* num_w=0;semid_rw=semget(RWSEMKEY,1,flags|IPC

20、_CREAT);semid_ww=semget(WWSEMKEY,1,flags|IPC_CREAT);semctl(semid_rw,0,SETVAL,1);semctl(semid_ww,0,SETVAL,1);num=i;for(i=0;inum;i+)while(j=fork()=-1);if(!j)if(msgi.decr=W)Write(msgi);else if(msgi.decr=R)Read(msgi);elseprintf(“n“);return 1;exit(0);for(i=0;inum;i+)wait();semctl(semid_rw,IPC_RMID,0);semctl(semid_ww,IPC_RMID,0);shmctl(shmid,IPC_RMID,0);return 1;

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。